From 376c1ba2d04cf14782de1d1fe05fc5378467748b Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 29 Dec 2025 23:53:21 +0900 Subject: [PATCH] =?UTF-8?q?[20251229]=20BOJ=20/=20G4=20/=20=EC=B9=9C?= =?UTF-8?q?=EA=B5=AC=EB=B9=84=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\271\234\352\265\254\353\271\204.md" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "khj20006/202512/29 BOJ G4 \354\271\234\352\265\254\353\271\204.md" diff --git "a/khj20006/202512/29 BOJ G4 \354\271\234\352\265\254\353\271\204.md" "b/khj20006/202512/29 BOJ G4 \354\271\234\352\265\254\353\271\204.md" new file mode 100644 index 00000000..f09d1d57 --- /dev/null +++ "b/khj20006/202512/29 BOJ G4 \354\271\234\352\265\254\353\271\204.md" @@ -0,0 +1,32 @@ +```cpp +#include +using namespace std; + +int N, M, K, a[10001]{}, r[10001]{}; +int f(int x) { return x==r[x] ? x : r[x]=f(r[x]); } + +int main() { + cin.tie(0)->sync_with_stdio(0); + + cin>>N>>M>>K; + iota(r, r+N+1, 0); + for(int i=1;i<=N;i++) cin>>a[i]; + for(int u,v;M--;) { + cin>>u>>v; + int x = f(u), y = f(v); + if(x == y) continue; + a[y] = min(a[x], a[y]); + r[x] = y; + } + + bitset<10001> vis; + int tot = 0; + for(int i=1;i<=N;i++) if(!vis[f(i)]) { + vis[f(i)].flip(); + tot += a[f(i)]; + if(tot > K) return cout<<"Oh no", 0; + } + cout<