#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
using ll = long long;
int n,m,q;
int s[N],deg[N];
ll ans;
vector<tuple<ll,int,int>> edge;
int p[N];
int fp(int u){
return p[u]=u==p[u]?u:fp(p[u]);
}
bool uni(int u,int v){
u=fp(u),v=fp(v);
return u!=v?p[u]=v,true:false;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m >> q;
for(int i=1;i<=n;i++){
cin >> s[i];
ans-=s[i];
}
for(int i=0;i<m;i++){
int u,v;
cin >> u >> v;
edge.emplace_back(s[u]+s[v],u,v);
}
ans+=*max_element(s+1,s+n+1);
sort(edge.begin(),edge.end());
for(int i=1;i<=n;i++)p[i]=i;
for(auto [w,u,v]:edge)if(uni(u,v))ans+=w;
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
41 ms |
7636 KB |
Output is correct |
3 |
Correct |
40 ms |
7880 KB |
Output is correct |
4 |
Correct |
52 ms |
8092 KB |
Output is correct |
5 |
Correct |
52 ms |
8716 KB |
Output is correct |
6 |
Correct |
47 ms |
7380 KB |
Output is correct |
7 |
Correct |
59 ms |
8056 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
41 ms |
7636 KB |
Output is correct |
3 |
Correct |
40 ms |
7880 KB |
Output is correct |
4 |
Correct |
52 ms |
8092 KB |
Output is correct |
5 |
Correct |
52 ms |
8716 KB |
Output is correct |
6 |
Correct |
47 ms |
7380 KB |
Output is correct |
7 |
Correct |
59 ms |
8056 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
55 ms |
7892 KB |
Output is correct |
11 |
Correct |
48 ms |
8656 KB |
Output is correct |
12 |
Correct |
42 ms |
7116 KB |
Output is correct |
13 |
Correct |
44 ms |
7116 KB |
Output is correct |
14 |
Correct |
56 ms |
8148 KB |
Output is correct |
15 |
Correct |
56 ms |
7628 KB |
Output is correct |
16 |
Correct |
55 ms |
7176 KB |
Output is correct |
17 |
Correct |
71 ms |
7880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
41 ms |
7636 KB |
Output is correct |
3 |
Correct |
40 ms |
7880 KB |
Output is correct |
4 |
Correct |
52 ms |
8092 KB |
Output is correct |
5 |
Correct |
52 ms |
8716 KB |
Output is correct |
6 |
Correct |
47 ms |
7380 KB |
Output is correct |
7 |
Correct |
59 ms |
8056 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
55 ms |
7892 KB |
Output is correct |
11 |
Correct |
48 ms |
8656 KB |
Output is correct |
12 |
Correct |
42 ms |
7116 KB |
Output is correct |
13 |
Correct |
44 ms |
7116 KB |
Output is correct |
14 |
Correct |
56 ms |
8148 KB |
Output is correct |
15 |
Correct |
56 ms |
7628 KB |
Output is correct |
16 |
Correct |
55 ms |
7176 KB |
Output is correct |
17 |
Correct |
71 ms |
7880 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
59 ms |
7628 KB |
Output is correct |
20 |
Correct |
60 ms |
7612 KB |
Output is correct |
21 |
Correct |
61 ms |
6860 KB |
Output is correct |
22 |
Correct |
61 ms |
8644 KB |
Output is correct |
23 |
Correct |
60 ms |
7112 KB |
Output is correct |
24 |
Correct |
61 ms |
7528 KB |
Output is correct |
25 |
Correct |
57 ms |
7096 KB |
Output is correct |
26 |
Correct |
65 ms |
8132 KB |
Output is correct |
27 |
Correct |
57 ms |
7380 KB |
Output is correct |
28 |
Correct |
61 ms |
7176 KB |
Output is correct |
29 |
Correct |
59 ms |
6864 KB |
Output is correct |
30 |
Correct |
58 ms |
8768 KB |
Output is correct |
31 |
Correct |
58 ms |
7892 KB |
Output is correct |
32 |
Correct |
63 ms |
7112 KB |
Output is correct |
33 |
Correct |
59 ms |
8136 KB |
Output is correct |
34 |
Correct |
64 ms |
6860 KB |
Output is correct |
35 |
Correct |
64 ms |
8260 KB |
Output is correct |
36 |
Correct |
63 ms |
8400 KB |
Output is correct |
37 |
Correct |
64 ms |
7624 KB |
Output is correct |
38 |
Correct |
67 ms |
6844 KB |
Output is correct |
39 |
Correct |
76 ms |
7368 KB |
Output is correct |
40 |
Correct |
60 ms |
8200 KB |
Output is correct |
41 |
Correct |
58 ms |
6836 KB |
Output is correct |
42 |
Correct |
56 ms |
8612 KB |
Output is correct |
43 |
Correct |
64 ms |
7880 KB |
Output is correct |
44 |
Correct |
68 ms |
8552 KB |
Output is correct |
45 |
Correct |
66 ms |
7884 KB |
Output is correct |
46 |
Correct |
66 ms |
8396 KB |
Output is correct |
47 |
Correct |
65 ms |
8136 KB |
Output is correct |
48 |
Correct |
71 ms |
7236 KB |
Output is correct |
49 |
Correct |
71 ms |
6856 KB |
Output is correct |
50 |
Correct |
60 ms |
7116 KB |
Output is correct |
51 |
Correct |
67 ms |
7368 KB |
Output is correct |
52 |
Correct |
56 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
41 ms |
7636 KB |
Output is correct |
3 |
Correct |
40 ms |
7880 KB |
Output is correct |
4 |
Correct |
52 ms |
8092 KB |
Output is correct |
5 |
Correct |
52 ms |
8716 KB |
Output is correct |
6 |
Correct |
47 ms |
7380 KB |
Output is correct |
7 |
Correct |
59 ms |
8056 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
55 ms |
7892 KB |
Output is correct |
11 |
Correct |
48 ms |
8656 KB |
Output is correct |
12 |
Correct |
42 ms |
7116 KB |
Output is correct |
13 |
Correct |
44 ms |
7116 KB |
Output is correct |
14 |
Correct |
56 ms |
8148 KB |
Output is correct |
15 |
Correct |
56 ms |
7628 KB |
Output is correct |
16 |
Correct |
55 ms |
7176 KB |
Output is correct |
17 |
Correct |
71 ms |
7880 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
59 ms |
7628 KB |
Output is correct |
20 |
Correct |
60 ms |
7612 KB |
Output is correct |
21 |
Correct |
61 ms |
6860 KB |
Output is correct |
22 |
Correct |
61 ms |
8644 KB |
Output is correct |
23 |
Correct |
60 ms |
7112 KB |
Output is correct |
24 |
Correct |
61 ms |
7528 KB |
Output is correct |
25 |
Correct |
57 ms |
7096 KB |
Output is correct |
26 |
Correct |
65 ms |
8132 KB |
Output is correct |
27 |
Correct |
57 ms |
7380 KB |
Output is correct |
28 |
Correct |
61 ms |
7176 KB |
Output is correct |
29 |
Correct |
59 ms |
6864 KB |
Output is correct |
30 |
Correct |
58 ms |
8768 KB |
Output is correct |
31 |
Correct |
58 ms |
7892 KB |
Output is correct |
32 |
Correct |
63 ms |
7112 KB |
Output is correct |
33 |
Correct |
59 ms |
8136 KB |
Output is correct |
34 |
Correct |
64 ms |
6860 KB |
Output is correct |
35 |
Correct |
64 ms |
8260 KB |
Output is correct |
36 |
Correct |
63 ms |
8400 KB |
Output is correct |
37 |
Correct |
64 ms |
7624 KB |
Output is correct |
38 |
Correct |
67 ms |
6844 KB |
Output is correct |
39 |
Correct |
76 ms |
7368 KB |
Output is correct |
40 |
Correct |
60 ms |
8200 KB |
Output is correct |
41 |
Correct |
58 ms |
6836 KB |
Output is correct |
42 |
Correct |
56 ms |
8612 KB |
Output is correct |
43 |
Correct |
64 ms |
7880 KB |
Output is correct |
44 |
Correct |
68 ms |
8552 KB |
Output is correct |
45 |
Correct |
66 ms |
7884 KB |
Output is correct |
46 |
Correct |
66 ms |
8396 KB |
Output is correct |
47 |
Correct |
65 ms |
8136 KB |
Output is correct |
48 |
Correct |
71 ms |
7236 KB |
Output is correct |
49 |
Correct |
71 ms |
6856 KB |
Output is correct |
50 |
Correct |
60 ms |
7116 KB |
Output is correct |
51 |
Correct |
67 ms |
7368 KB |
Output is correct |
52 |
Correct |
56 ms |
7372 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
63 ms |
12408 KB |
Output is correct |
55 |
Correct |
63 ms |
11724 KB |
Output is correct |
56 |
Correct |
76 ms |
17580 KB |
Output is correct |
57 |
Correct |
108 ms |
18020 KB |
Output is correct |
58 |
Correct |
109 ms |
18196 KB |
Output is correct |
59 |
Correct |
108 ms |
18376 KB |
Output is correct |
60 |
Correct |
82 ms |
17044 KB |
Output is correct |
61 |
Correct |
116 ms |
16348 KB |
Output is correct |
62 |
Correct |
106 ms |
16836 KB |
Output is correct |
63 |
Correct |
63 ms |
12132 KB |
Output is correct |
64 |
Correct |
84 ms |
17596 KB |
Output is correct |
65 |
Correct |
108 ms |
18112 KB |
Output is correct |
66 |
Correct |
114 ms |
17728 KB |
Output is correct |
67 |
Correct |
108 ms |
16316 KB |
Output is correct |
68 |
Correct |
59 ms |
10696 KB |
Output is correct |
69 |
Correct |
102 ms |
18112 KB |
Output is correct |
70 |
Correct |
74 ms |
11200 KB |
Output is correct |
71 |
Correct |
64 ms |
12748 KB |
Output is correct |
72 |
Correct |
62 ms |
11328 KB |
Output is correct |
73 |
Correct |
67 ms |
12240 KB |
Output is correct |
74 |
Correct |
61 ms |
12072 KB |
Output is correct |
75 |
Correct |
61 ms |
12240 KB |
Output is correct |
76 |
Correct |
56 ms |
10952 KB |
Output is correct |
77 |
Correct |
58 ms |
11088 KB |
Output is correct |
78 |
Correct |
69 ms |
12232 KB |
Output is correct |
79 |
Correct |
118 ms |
17348 KB |
Output is correct |
80 |
Correct |
87 ms |
12064 KB |
Output is correct |
81 |
Correct |
108 ms |
16832 KB |
Output is correct |
82 |
Correct |
121 ms |
18132 KB |
Output is correct |
83 |
Correct |
115 ms |
16992 KB |
Output is correct |
84 |
Correct |
118 ms |
17996 KB |
Output is correct |
85 |
Correct |
63 ms |
12212 KB |
Output is correct |
86 |
Correct |
67 ms |
11724 KB |
Output is correct |
87 |
Correct |
59 ms |
10188 KB |
Output is correct |
88 |
Correct |
119 ms |
16832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
41 ms |
7636 KB |
Output is correct |
3 |
Correct |
40 ms |
7880 KB |
Output is correct |
4 |
Correct |
52 ms |
8092 KB |
Output is correct |
5 |
Correct |
52 ms |
8716 KB |
Output is correct |
6 |
Correct |
47 ms |
7380 KB |
Output is correct |
7 |
Correct |
59 ms |
8056 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
55 ms |
7892 KB |
Output is correct |
11 |
Correct |
48 ms |
8656 KB |
Output is correct |
12 |
Correct |
42 ms |
7116 KB |
Output is correct |
13 |
Correct |
44 ms |
7116 KB |
Output is correct |
14 |
Correct |
56 ms |
8148 KB |
Output is correct |
15 |
Correct |
56 ms |
7628 KB |
Output is correct |
16 |
Correct |
55 ms |
7176 KB |
Output is correct |
17 |
Correct |
71 ms |
7880 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
59 ms |
7628 KB |
Output is correct |
20 |
Correct |
60 ms |
7612 KB |
Output is correct |
21 |
Correct |
61 ms |
6860 KB |
Output is correct |
22 |
Correct |
61 ms |
8644 KB |
Output is correct |
23 |
Correct |
60 ms |
7112 KB |
Output is correct |
24 |
Correct |
61 ms |
7528 KB |
Output is correct |
25 |
Correct |
57 ms |
7096 KB |
Output is correct |
26 |
Correct |
65 ms |
8132 KB |
Output is correct |
27 |
Correct |
57 ms |
7380 KB |
Output is correct |
28 |
Correct |
61 ms |
7176 KB |
Output is correct |
29 |
Correct |
59 ms |
6864 KB |
Output is correct |
30 |
Correct |
58 ms |
8768 KB |
Output is correct |
31 |
Correct |
58 ms |
7892 KB |
Output is correct |
32 |
Correct |
63 ms |
7112 KB |
Output is correct |
33 |
Correct |
59 ms |
8136 KB |
Output is correct |
34 |
Correct |
64 ms |
6860 KB |
Output is correct |
35 |
Correct |
64 ms |
8260 KB |
Output is correct |
36 |
Correct |
63 ms |
8400 KB |
Output is correct |
37 |
Correct |
64 ms |
7624 KB |
Output is correct |
38 |
Correct |
67 ms |
6844 KB |
Output is correct |
39 |
Correct |
76 ms |
7368 KB |
Output is correct |
40 |
Correct |
60 ms |
8200 KB |
Output is correct |
41 |
Correct |
58 ms |
6836 KB |
Output is correct |
42 |
Correct |
56 ms |
8612 KB |
Output is correct |
43 |
Correct |
64 ms |
7880 KB |
Output is correct |
44 |
Correct |
68 ms |
8552 KB |
Output is correct |
45 |
Correct |
66 ms |
7884 KB |
Output is correct |
46 |
Correct |
66 ms |
8396 KB |
Output is correct |
47 |
Correct |
65 ms |
8136 KB |
Output is correct |
48 |
Correct |
71 ms |
7236 KB |
Output is correct |
49 |
Correct |
71 ms |
6856 KB |
Output is correct |
50 |
Correct |
60 ms |
7116 KB |
Output is correct |
51 |
Correct |
67 ms |
7368 KB |
Output is correct |
52 |
Correct |
56 ms |
7372 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
63 ms |
12408 KB |
Output is correct |
55 |
Correct |
63 ms |
11724 KB |
Output is correct |
56 |
Correct |
76 ms |
17580 KB |
Output is correct |
57 |
Correct |
108 ms |
18020 KB |
Output is correct |
58 |
Correct |
109 ms |
18196 KB |
Output is correct |
59 |
Correct |
108 ms |
18376 KB |
Output is correct |
60 |
Correct |
82 ms |
17044 KB |
Output is correct |
61 |
Correct |
116 ms |
16348 KB |
Output is correct |
62 |
Correct |
106 ms |
16836 KB |
Output is correct |
63 |
Correct |
63 ms |
12132 KB |
Output is correct |
64 |
Correct |
84 ms |
17596 KB |
Output is correct |
65 |
Correct |
108 ms |
18112 KB |
Output is correct |
66 |
Correct |
114 ms |
17728 KB |
Output is correct |
67 |
Correct |
108 ms |
16316 KB |
Output is correct |
68 |
Correct |
59 ms |
10696 KB |
Output is correct |
69 |
Correct |
102 ms |
18112 KB |
Output is correct |
70 |
Correct |
74 ms |
11200 KB |
Output is correct |
71 |
Correct |
64 ms |
12748 KB |
Output is correct |
72 |
Correct |
62 ms |
11328 KB |
Output is correct |
73 |
Correct |
67 ms |
12240 KB |
Output is correct |
74 |
Correct |
61 ms |
12072 KB |
Output is correct |
75 |
Correct |
61 ms |
12240 KB |
Output is correct |
76 |
Correct |
56 ms |
10952 KB |
Output is correct |
77 |
Correct |
58 ms |
11088 KB |
Output is correct |
78 |
Correct |
69 ms |
12232 KB |
Output is correct |
79 |
Correct |
118 ms |
17348 KB |
Output is correct |
80 |
Correct |
87 ms |
12064 KB |
Output is correct |
81 |
Correct |
108 ms |
16832 KB |
Output is correct |
82 |
Correct |
121 ms |
18132 KB |
Output is correct |
83 |
Correct |
115 ms |
16992 KB |
Output is correct |
84 |
Correct |
118 ms |
17996 KB |
Output is correct |
85 |
Correct |
63 ms |
12212 KB |
Output is correct |
86 |
Correct |
67 ms |
11724 KB |
Output is correct |
87 |
Correct |
59 ms |
10188 KB |
Output is correct |
88 |
Correct |
119 ms |
16832 KB |
Output is correct |
89 |
Correct |
2 ms |
2392 KB |
Output is correct |
90 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
91 |
Halted |
0 ms |
0 KB |
- |