/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
const int M_MAX = 400000;
const int Q_MAX = 200000;
int N, M, Q;
int S[N_MAX + 2];
int edge_u[M_MAX + 2], edge_v[M_MAX + 2];
int order[M_MAX + 2];
int root[N_MAX + 2];
int find_root (int u) {
return (root[u] == 0 ? u : root[u] = find_root(root[u]));
}
bool join (int u, int v) {
u = find_root(u);
v = find_root(v);
if (u != v) {
root[u] = v;
return true;
}
return false;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> Q;
assert(Q == 0);
for (int u = 1; u <= N; u++) {
cin >> S[u];
}
for (int i = 1; i <= M; i++) {
cin >> edge_u[i] >> edge_v[i];
}
iota(order + 1, order + M + 1, 1);
sort(order + 1, order + M + 1, [&] (const int &i, const int &j) {
return S[edge_u[i]] + S[edge_v[i]] < S[edge_u[j]] + S[edge_v[j]];
});
ll answer = 0;
for (int _ = 1; _ <= M; _++) {
int i = order[_];
if (join(edge_u[i], edge_v[i]) == true) {
answer += S[edge_u[i]] + S[edge_v[i]];
}
}
int mx = 0;
for (int u = 1; u <= N; u++) {
answer -= S[u];
mx = max(mx, S[u]);
}
answer += mx;
cout << answer << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
56 ms |
8784 KB |
Output is correct |
3 |
Correct |
37 ms |
8836 KB |
Output is correct |
4 |
Correct |
40 ms |
8764 KB |
Output is correct |
5 |
Correct |
45 ms |
8784 KB |
Output is correct |
6 |
Correct |
40 ms |
8784 KB |
Output is correct |
7 |
Correct |
39 ms |
8784 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
56 ms |
8784 KB |
Output is correct |
3 |
Correct |
37 ms |
8836 KB |
Output is correct |
4 |
Correct |
40 ms |
8764 KB |
Output is correct |
5 |
Correct |
45 ms |
8784 KB |
Output is correct |
6 |
Correct |
40 ms |
8784 KB |
Output is correct |
7 |
Correct |
39 ms |
8784 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
72 ms |
10172 KB |
Output is correct |
11 |
Correct |
47 ms |
10420 KB |
Output is correct |
12 |
Correct |
69 ms |
10320 KB |
Output is correct |
13 |
Correct |
65 ms |
10176 KB |
Output is correct |
14 |
Correct |
70 ms |
10176 KB |
Output is correct |
15 |
Correct |
68 ms |
10188 KB |
Output is correct |
16 |
Correct |
71 ms |
10220 KB |
Output is correct |
17 |
Correct |
66 ms |
10324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
56 ms |
8784 KB |
Output is correct |
3 |
Correct |
37 ms |
8836 KB |
Output is correct |
4 |
Correct |
40 ms |
8764 KB |
Output is correct |
5 |
Correct |
45 ms |
8784 KB |
Output is correct |
6 |
Correct |
40 ms |
8784 KB |
Output is correct |
7 |
Correct |
39 ms |
8784 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
72 ms |
10172 KB |
Output is correct |
11 |
Correct |
47 ms |
10420 KB |
Output is correct |
12 |
Correct |
69 ms |
10320 KB |
Output is correct |
13 |
Correct |
65 ms |
10176 KB |
Output is correct |
14 |
Correct |
70 ms |
10176 KB |
Output is correct |
15 |
Correct |
68 ms |
10188 KB |
Output is correct |
16 |
Correct |
71 ms |
10220 KB |
Output is correct |
17 |
Correct |
66 ms |
10324 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
91 ms |
10172 KB |
Output is correct |
20 |
Correct |
71 ms |
10148 KB |
Output is correct |
21 |
Correct |
92 ms |
10184 KB |
Output is correct |
22 |
Correct |
75 ms |
10212 KB |
Output is correct |
23 |
Correct |
74 ms |
10304 KB |
Output is correct |
24 |
Correct |
103 ms |
10320 KB |
Output is correct |
25 |
Correct |
70 ms |
10324 KB |
Output is correct |
26 |
Correct |
69 ms |
10068 KB |
Output is correct |
27 |
Correct |
68 ms |
10200 KB |
Output is correct |
28 |
Correct |
77 ms |
10232 KB |
Output is correct |
29 |
Correct |
83 ms |
10324 KB |
Output is correct |
30 |
Correct |
84 ms |
10688 KB |
Output is correct |
31 |
Correct |
68 ms |
10324 KB |
Output is correct |
32 |
Correct |
92 ms |
10324 KB |
Output is correct |
33 |
Correct |
50 ms |
9808 KB |
Output is correct |
34 |
Correct |
66 ms |
10280 KB |
Output is correct |
35 |
Correct |
62 ms |
10360 KB |
Output is correct |
36 |
Correct |
56 ms |
10396 KB |
Output is correct |
37 |
Correct |
58 ms |
10464 KB |
Output is correct |
38 |
Correct |
59 ms |
10072 KB |
Output is correct |
39 |
Correct |
60 ms |
10844 KB |
Output is correct |
40 |
Correct |
59 ms |
10424 KB |
Output is correct |
41 |
Correct |
73 ms |
9532 KB |
Output is correct |
42 |
Correct |
66 ms |
9540 KB |
Output is correct |
43 |
Correct |
56 ms |
10092 KB |
Output is correct |
44 |
Correct |
92 ms |
10320 KB |
Output is correct |
45 |
Correct |
58 ms |
10312 KB |
Output is correct |
46 |
Correct |
64 ms |
10320 KB |
Output is correct |
47 |
Correct |
61 ms |
10188 KB |
Output is correct |
48 |
Correct |
67 ms |
10232 KB |
Output is correct |
49 |
Correct |
73 ms |
10308 KB |
Output is correct |
50 |
Correct |
72 ms |
10324 KB |
Output is correct |
51 |
Correct |
54 ms |
10576 KB |
Output is correct |
52 |
Correct |
46 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
56 ms |
8784 KB |
Output is correct |
3 |
Correct |
37 ms |
8836 KB |
Output is correct |
4 |
Correct |
40 ms |
8764 KB |
Output is correct |
5 |
Correct |
45 ms |
8784 KB |
Output is correct |
6 |
Correct |
40 ms |
8784 KB |
Output is correct |
7 |
Correct |
39 ms |
8784 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
72 ms |
10172 KB |
Output is correct |
11 |
Correct |
47 ms |
10420 KB |
Output is correct |
12 |
Correct |
69 ms |
10320 KB |
Output is correct |
13 |
Correct |
65 ms |
10176 KB |
Output is correct |
14 |
Correct |
70 ms |
10176 KB |
Output is correct |
15 |
Correct |
68 ms |
10188 KB |
Output is correct |
16 |
Correct |
71 ms |
10220 KB |
Output is correct |
17 |
Correct |
66 ms |
10324 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
91 ms |
10172 KB |
Output is correct |
20 |
Correct |
71 ms |
10148 KB |
Output is correct |
21 |
Correct |
92 ms |
10184 KB |
Output is correct |
22 |
Correct |
75 ms |
10212 KB |
Output is correct |
23 |
Correct |
74 ms |
10304 KB |
Output is correct |
24 |
Correct |
103 ms |
10320 KB |
Output is correct |
25 |
Correct |
70 ms |
10324 KB |
Output is correct |
26 |
Correct |
69 ms |
10068 KB |
Output is correct |
27 |
Correct |
68 ms |
10200 KB |
Output is correct |
28 |
Correct |
77 ms |
10232 KB |
Output is correct |
29 |
Correct |
83 ms |
10324 KB |
Output is correct |
30 |
Correct |
84 ms |
10688 KB |
Output is correct |
31 |
Correct |
68 ms |
10324 KB |
Output is correct |
32 |
Correct |
92 ms |
10324 KB |
Output is correct |
33 |
Correct |
50 ms |
9808 KB |
Output is correct |
34 |
Correct |
66 ms |
10280 KB |
Output is correct |
35 |
Correct |
62 ms |
10360 KB |
Output is correct |
36 |
Correct |
56 ms |
10396 KB |
Output is correct |
37 |
Correct |
58 ms |
10464 KB |
Output is correct |
38 |
Correct |
59 ms |
10072 KB |
Output is correct |
39 |
Correct |
60 ms |
10844 KB |
Output is correct |
40 |
Correct |
59 ms |
10424 KB |
Output is correct |
41 |
Correct |
73 ms |
9532 KB |
Output is correct |
42 |
Correct |
66 ms |
9540 KB |
Output is correct |
43 |
Correct |
56 ms |
10092 KB |
Output is correct |
44 |
Correct |
92 ms |
10320 KB |
Output is correct |
45 |
Correct |
58 ms |
10312 KB |
Output is correct |
46 |
Correct |
64 ms |
10320 KB |
Output is correct |
47 |
Correct |
61 ms |
10188 KB |
Output is correct |
48 |
Correct |
67 ms |
10232 KB |
Output is correct |
49 |
Correct |
73 ms |
10308 KB |
Output is correct |
50 |
Correct |
72 ms |
10324 KB |
Output is correct |
51 |
Correct |
54 ms |
10576 KB |
Output is correct |
52 |
Correct |
46 ms |
8792 KB |
Output is correct |
53 |
Correct |
1 ms |
4440 KB |
Output is correct |
54 |
Correct |
81 ms |
10364 KB |
Output is correct |
55 |
Correct |
77 ms |
10412 KB |
Output is correct |
56 |
Correct |
94 ms |
11240 KB |
Output is correct |
57 |
Correct |
138 ms |
13504 KB |
Output is correct |
58 |
Correct |
136 ms |
13504 KB |
Output is correct |
59 |
Correct |
138 ms |
13648 KB |
Output is correct |
60 |
Correct |
99 ms |
11912 KB |
Output is correct |
61 |
Correct |
140 ms |
13388 KB |
Output is correct |
62 |
Correct |
144 ms |
13612 KB |
Output is correct |
63 |
Correct |
75 ms |
10616 KB |
Output is correct |
64 |
Correct |
104 ms |
11772 KB |
Output is correct |
65 |
Correct |
136 ms |
13732 KB |
Output is correct |
66 |
Correct |
137 ms |
13452 KB |
Output is correct |
67 |
Correct |
139 ms |
13480 KB |
Output is correct |
68 |
Correct |
50 ms |
9336 KB |
Output is correct |
69 |
Correct |
121 ms |
12372 KB |
Output is correct |
70 |
Correct |
76 ms |
10796 KB |
Output is correct |
71 |
Correct |
70 ms |
10596 KB |
Output is correct |
72 |
Correct |
71 ms |
10564 KB |
Output is correct |
73 |
Correct |
61 ms |
10064 KB |
Output is correct |
74 |
Correct |
61 ms |
10760 KB |
Output is correct |
75 |
Correct |
78 ms |
10324 KB |
Output is correct |
76 |
Correct |
66 ms |
9552 KB |
Output is correct |
77 |
Correct |
66 ms |
9536 KB |
Output is correct |
78 |
Correct |
60 ms |
10588 KB |
Output is correct |
79 |
Correct |
164 ms |
13504 KB |
Output is correct |
80 |
Correct |
75 ms |
11348 KB |
Output is correct |
81 |
Correct |
96 ms |
13036 KB |
Output is correct |
82 |
Correct |
103 ms |
13532 KB |
Output is correct |
83 |
Correct |
124 ms |
13540 KB |
Output is correct |
84 |
Correct |
143 ms |
13648 KB |
Output is correct |
85 |
Correct |
82 ms |
10324 KB |
Output is correct |
86 |
Correct |
62 ms |
10452 KB |
Output is correct |
87 |
Correct |
49 ms |
8904 KB |
Output is correct |
88 |
Correct |
145 ms |
13644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
56 ms |
8784 KB |
Output is correct |
3 |
Correct |
37 ms |
8836 KB |
Output is correct |
4 |
Correct |
40 ms |
8764 KB |
Output is correct |
5 |
Correct |
45 ms |
8784 KB |
Output is correct |
6 |
Correct |
40 ms |
8784 KB |
Output is correct |
7 |
Correct |
39 ms |
8784 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
72 ms |
10172 KB |
Output is correct |
11 |
Correct |
47 ms |
10420 KB |
Output is correct |
12 |
Correct |
69 ms |
10320 KB |
Output is correct |
13 |
Correct |
65 ms |
10176 KB |
Output is correct |
14 |
Correct |
70 ms |
10176 KB |
Output is correct |
15 |
Correct |
68 ms |
10188 KB |
Output is correct |
16 |
Correct |
71 ms |
10220 KB |
Output is correct |
17 |
Correct |
66 ms |
10324 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
91 ms |
10172 KB |
Output is correct |
20 |
Correct |
71 ms |
10148 KB |
Output is correct |
21 |
Correct |
92 ms |
10184 KB |
Output is correct |
22 |
Correct |
75 ms |
10212 KB |
Output is correct |
23 |
Correct |
74 ms |
10304 KB |
Output is correct |
24 |
Correct |
103 ms |
10320 KB |
Output is correct |
25 |
Correct |
70 ms |
10324 KB |
Output is correct |
26 |
Correct |
69 ms |
10068 KB |
Output is correct |
27 |
Correct |
68 ms |
10200 KB |
Output is correct |
28 |
Correct |
77 ms |
10232 KB |
Output is correct |
29 |
Correct |
83 ms |
10324 KB |
Output is correct |
30 |
Correct |
84 ms |
10688 KB |
Output is correct |
31 |
Correct |
68 ms |
10324 KB |
Output is correct |
32 |
Correct |
92 ms |
10324 KB |
Output is correct |
33 |
Correct |
50 ms |
9808 KB |
Output is correct |
34 |
Correct |
66 ms |
10280 KB |
Output is correct |
35 |
Correct |
62 ms |
10360 KB |
Output is correct |
36 |
Correct |
56 ms |
10396 KB |
Output is correct |
37 |
Correct |
58 ms |
10464 KB |
Output is correct |
38 |
Correct |
59 ms |
10072 KB |
Output is correct |
39 |
Correct |
60 ms |
10844 KB |
Output is correct |
40 |
Correct |
59 ms |
10424 KB |
Output is correct |
41 |
Correct |
73 ms |
9532 KB |
Output is correct |
42 |
Correct |
66 ms |
9540 KB |
Output is correct |
43 |
Correct |
56 ms |
10092 KB |
Output is correct |
44 |
Correct |
92 ms |
10320 KB |
Output is correct |
45 |
Correct |
58 ms |
10312 KB |
Output is correct |
46 |
Correct |
64 ms |
10320 KB |
Output is correct |
47 |
Correct |
61 ms |
10188 KB |
Output is correct |
48 |
Correct |
67 ms |
10232 KB |
Output is correct |
49 |
Correct |
73 ms |
10308 KB |
Output is correct |
50 |
Correct |
72 ms |
10324 KB |
Output is correct |
51 |
Correct |
54 ms |
10576 KB |
Output is correct |
52 |
Correct |
46 ms |
8792 KB |
Output is correct |
53 |
Correct |
1 ms |
4440 KB |
Output is correct |
54 |
Correct |
81 ms |
10364 KB |
Output is correct |
55 |
Correct |
77 ms |
10412 KB |
Output is correct |
56 |
Correct |
94 ms |
11240 KB |
Output is correct |
57 |
Correct |
138 ms |
13504 KB |
Output is correct |
58 |
Correct |
136 ms |
13504 KB |
Output is correct |
59 |
Correct |
138 ms |
13648 KB |
Output is correct |
60 |
Correct |
99 ms |
11912 KB |
Output is correct |
61 |
Correct |
140 ms |
13388 KB |
Output is correct |
62 |
Correct |
144 ms |
13612 KB |
Output is correct |
63 |
Correct |
75 ms |
10616 KB |
Output is correct |
64 |
Correct |
104 ms |
11772 KB |
Output is correct |
65 |
Correct |
136 ms |
13732 KB |
Output is correct |
66 |
Correct |
137 ms |
13452 KB |
Output is correct |
67 |
Correct |
139 ms |
13480 KB |
Output is correct |
68 |
Correct |
50 ms |
9336 KB |
Output is correct |
69 |
Correct |
121 ms |
12372 KB |
Output is correct |
70 |
Correct |
76 ms |
10796 KB |
Output is correct |
71 |
Correct |
70 ms |
10596 KB |
Output is correct |
72 |
Correct |
71 ms |
10564 KB |
Output is correct |
73 |
Correct |
61 ms |
10064 KB |
Output is correct |
74 |
Correct |
61 ms |
10760 KB |
Output is correct |
75 |
Correct |
78 ms |
10324 KB |
Output is correct |
76 |
Correct |
66 ms |
9552 KB |
Output is correct |
77 |
Correct |
66 ms |
9536 KB |
Output is correct |
78 |
Correct |
60 ms |
10588 KB |
Output is correct |
79 |
Correct |
164 ms |
13504 KB |
Output is correct |
80 |
Correct |
75 ms |
11348 KB |
Output is correct |
81 |
Correct |
96 ms |
13036 KB |
Output is correct |
82 |
Correct |
103 ms |
13532 KB |
Output is correct |
83 |
Correct |
124 ms |
13540 KB |
Output is correct |
84 |
Correct |
143 ms |
13648 KB |
Output is correct |
85 |
Correct |
82 ms |
10324 KB |
Output is correct |
86 |
Correct |
62 ms |
10452 KB |
Output is correct |
87 |
Correct |
49 ms |
8904 KB |
Output is correct |
88 |
Correct |
145 ms |
13644 KB |
Output is correct |
89 |
Correct |
1 ms |
4440 KB |
Output is correct |
90 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
91 |
Halted |
0 ms |
0 KB |
- |