forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
44 lines (37 loc) · 841 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/caef773ebb994d6e854c390d5fe22057
#include<bits/stdc++.h>
using namespace std;
int uf[10101], arr[10101];
int find(int x) {
if(uf[x] < 0) return x;
return uf[x] = find(uf[x]);
}
bool merge(int a, int b) {
a = find(a);
b = find(b);
if(a == b) return false;
uf[b] = a;
arr[a] = min(arr[a], arr[b]);
arr[b] = 0;
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k; cin >> n >> m >> k;
for(int i=1;i<=n;i++) {
uf[i] = -1;
cin >> arr[i];
}
for(int i=0;i<m;i++) {
int a, b; cin >> a >> b;
merge(a, b);
}
int answer = 0;
for(int i=1;i<=n;i++) answer += arr[i];
if(answer > k) cout << "Oh no";
else cout << answer;
return 0;
}