Skip to content

Commit 376c1ba

Browse files
authored
[20251229] BOJ / G4 / 친구비 / 권혁준
1 parent 5385703 commit 376c1ba

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```cpp
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int N, M, K, a[10001]{}, r[10001]{};
6+
int f(int x) { return x==r[x] ? x : r[x]=f(r[x]); }
7+
8+
int main() {
9+
cin.tie(0)->sync_with_stdio(0);
10+
11+
cin>>N>>M>>K;
12+
iota(r, r+N+1, 0);
13+
for(int i=1;i<=N;i++) cin>>a[i];
14+
for(int u,v;M--;) {
15+
cin>>u>>v;
16+
int x = f(u), y = f(v);
17+
if(x == y) continue;
18+
a[y] = min(a[x], a[y]);
19+
r[x] = y;
20+
}
21+
22+
bitset<10001> vis;
23+
int tot = 0;
24+
for(int i=1;i<=N;i++) if(!vis[f(i)]) {
25+
vis[f(i)].flip();
26+
tot += a[f(i)];
27+
if(tot > K) return cout<<"Oh no", 0;
28+
}
29+
cout<<tot;
30+
31+
}
32+
```

0 commit comments

Comments
 (0)