#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF2 = 4e18;
ll ans;
struct DSU{
int path[200200];
void init(int n){for (int i=1;i<=n;i++) path[i] = i;}
int find(int s){
if (s==path[s]) return s;
return path[s] = find(path[s]);
}
int merge(int s, int v){
s = find(s), v = find(v);
if (s==v) return 0;
path[v] = s;
return 1;
}
}dsu;
vector<int> adj[200200], G[200200];
ll a[200200];
int par[200200], deg[200200];
void dfs(int s, int pa){
par[s] = pa;
ans += a[pa];
for (auto &v:G[s]) if (v!=pa) dfs(v, s);
}
int main(){
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
for (int i=1;i<=n;i++) scanf("%lld", a+i);
int root = max_element(a+1, a+n+1) - a;
for (int i=1;i<=m;i++){
int x, y;
scanf("%d %d", &x, &y);
adj[x].push_back(y);
adj[y].push_back(x);
}
vector<array<ll, 3>> E;
dsu.init(n);
for (int i=1;i<=n;i++){
for (auto &v:adj[i]) if (dsu.find(i) != dsu.find(v)){
E.push_back({a[i] + a[v], i, v});
}
}
sort(E.begin(), E.end());
vector<pair<int, int>> Edge;
for (auto &[z, x, y]:E) if (dsu.merge(x, y)){
G[x].push_back(y);
G[y].push_back(x);
Edge.emplace_back(x, y);
}
ans = a[root];
for (int i=1;i<=n;i++) ans -= a[i];
for (auto &[v, w]:Edge) ans += a[v] + a[w];
printf("%lld\n", ans);
}
Compilation message
guard.cpp: In function 'int main()':
guard.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%d %d %d", &n, &m, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
guard.cpp:39:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | for (int i=1;i<=n;i++) scanf("%lld", a+i);
| ~~~~~^~~~~~~~~~~~~
guard.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
131 ms |
35516 KB |
Output is correct |
3 |
Correct |
113 ms |
35428 KB |
Output is correct |
4 |
Correct |
128 ms |
35472 KB |
Output is correct |
5 |
Correct |
128 ms |
35620 KB |
Output is correct |
6 |
Correct |
127 ms |
35520 KB |
Output is correct |
7 |
Correct |
125 ms |
35528 KB |
Output is correct |
8 |
Correct |
5 ms |
9720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
131 ms |
35516 KB |
Output is correct |
3 |
Correct |
113 ms |
35428 KB |
Output is correct |
4 |
Correct |
128 ms |
35472 KB |
Output is correct |
5 |
Correct |
128 ms |
35620 KB |
Output is correct |
6 |
Correct |
127 ms |
35520 KB |
Output is correct |
7 |
Correct |
125 ms |
35528 KB |
Output is correct |
8 |
Correct |
5 ms |
9720 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
194 ms |
35612 KB |
Output is correct |
11 |
Correct |
114 ms |
35520 KB |
Output is correct |
12 |
Correct |
106 ms |
35536 KB |
Output is correct |
13 |
Correct |
102 ms |
35524 KB |
Output is correct |
14 |
Correct |
144 ms |
35524 KB |
Output is correct |
15 |
Correct |
154 ms |
35500 KB |
Output is correct |
16 |
Correct |
164 ms |
35420 KB |
Output is correct |
17 |
Correct |
147 ms |
35520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
131 ms |
35516 KB |
Output is correct |
3 |
Correct |
113 ms |
35428 KB |
Output is correct |
4 |
Correct |
128 ms |
35472 KB |
Output is correct |
5 |
Correct |
128 ms |
35620 KB |
Output is correct |
6 |
Correct |
127 ms |
35520 KB |
Output is correct |
7 |
Correct |
125 ms |
35528 KB |
Output is correct |
8 |
Correct |
5 ms |
9720 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
194 ms |
35612 KB |
Output is correct |
11 |
Correct |
114 ms |
35520 KB |
Output is correct |
12 |
Correct |
106 ms |
35536 KB |
Output is correct |
13 |
Correct |
102 ms |
35524 KB |
Output is correct |
14 |
Correct |
144 ms |
35524 KB |
Output is correct |
15 |
Correct |
154 ms |
35500 KB |
Output is correct |
16 |
Correct |
164 ms |
35420 KB |
Output is correct |
17 |
Correct |
147 ms |
35520 KB |
Output is correct |
18 |
Correct |
6 ms |
9684 KB |
Output is correct |
19 |
Correct |
194 ms |
35448 KB |
Output is correct |
20 |
Correct |
195 ms |
35456 KB |
Output is correct |
21 |
Correct |
184 ms |
35640 KB |
Output is correct |
22 |
Correct |
189 ms |
35868 KB |
Output is correct |
23 |
Correct |
167 ms |
37296 KB |
Output is correct |
24 |
Correct |
184 ms |
37428 KB |
Output is correct |
25 |
Correct |
161 ms |
37088 KB |
Output is correct |
26 |
Correct |
194 ms |
37084 KB |
Output is correct |
27 |
Correct |
155 ms |
37076 KB |
Output is correct |
28 |
Correct |
186 ms |
35916 KB |
Output is correct |
29 |
Correct |
181 ms |
36280 KB |
Output is correct |
30 |
Correct |
177 ms |
36956 KB |
Output is correct |
31 |
Correct |
156 ms |
37084 KB |
Output is correct |
32 |
Correct |
183 ms |
36392 KB |
Output is correct |
33 |
Correct |
206 ms |
35520 KB |
Output is correct |
34 |
Correct |
180 ms |
35576 KB |
Output is correct |
35 |
Correct |
172 ms |
37404 KB |
Output is correct |
36 |
Correct |
162 ms |
37648 KB |
Output is correct |
37 |
Correct |
195 ms |
37612 KB |
Output is correct |
38 |
Correct |
166 ms |
36300 KB |
Output is correct |
39 |
Correct |
169 ms |
36944 KB |
Output is correct |
40 |
Correct |
165 ms |
36580 KB |
Output is correct |
41 |
Correct |
174 ms |
35520 KB |
Output is correct |
42 |
Correct |
159 ms |
35508 KB |
Output is correct |
43 |
Correct |
186 ms |
35868 KB |
Output is correct |
44 |
Correct |
201 ms |
36000 KB |
Output is correct |
45 |
Correct |
192 ms |
35968 KB |
Output is correct |
46 |
Correct |
204 ms |
35916 KB |
Output is correct |
47 |
Correct |
204 ms |
36032 KB |
Output is correct |
48 |
Correct |
186 ms |
35876 KB |
Output is correct |
49 |
Correct |
183 ms |
35952 KB |
Output is correct |
50 |
Correct |
185 ms |
35936 KB |
Output is correct |
51 |
Correct |
178 ms |
35912 KB |
Output is correct |
52 |
Correct |
186 ms |
35960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
131 ms |
35516 KB |
Output is correct |
3 |
Correct |
113 ms |
35428 KB |
Output is correct |
4 |
Correct |
128 ms |
35472 KB |
Output is correct |
5 |
Correct |
128 ms |
35620 KB |
Output is correct |
6 |
Correct |
127 ms |
35520 KB |
Output is correct |
7 |
Correct |
125 ms |
35528 KB |
Output is correct |
8 |
Correct |
5 ms |
9720 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
194 ms |
35612 KB |
Output is correct |
11 |
Correct |
114 ms |
35520 KB |
Output is correct |
12 |
Correct |
106 ms |
35536 KB |
Output is correct |
13 |
Correct |
102 ms |
35524 KB |
Output is correct |
14 |
Correct |
144 ms |
35524 KB |
Output is correct |
15 |
Correct |
154 ms |
35500 KB |
Output is correct |
16 |
Correct |
164 ms |
35420 KB |
Output is correct |
17 |
Correct |
147 ms |
35520 KB |
Output is correct |
18 |
Correct |
6 ms |
9684 KB |
Output is correct |
19 |
Correct |
194 ms |
35448 KB |
Output is correct |
20 |
Correct |
195 ms |
35456 KB |
Output is correct |
21 |
Correct |
184 ms |
35640 KB |
Output is correct |
22 |
Correct |
189 ms |
35868 KB |
Output is correct |
23 |
Correct |
167 ms |
37296 KB |
Output is correct |
24 |
Correct |
184 ms |
37428 KB |
Output is correct |
25 |
Correct |
161 ms |
37088 KB |
Output is correct |
26 |
Correct |
194 ms |
37084 KB |
Output is correct |
27 |
Correct |
155 ms |
37076 KB |
Output is correct |
28 |
Correct |
186 ms |
35916 KB |
Output is correct |
29 |
Correct |
181 ms |
36280 KB |
Output is correct |
30 |
Correct |
177 ms |
36956 KB |
Output is correct |
31 |
Correct |
156 ms |
37084 KB |
Output is correct |
32 |
Correct |
183 ms |
36392 KB |
Output is correct |
33 |
Correct |
206 ms |
35520 KB |
Output is correct |
34 |
Correct |
180 ms |
35576 KB |
Output is correct |
35 |
Correct |
172 ms |
37404 KB |
Output is correct |
36 |
Correct |
162 ms |
37648 KB |
Output is correct |
37 |
Correct |
195 ms |
37612 KB |
Output is correct |
38 |
Correct |
166 ms |
36300 KB |
Output is correct |
39 |
Correct |
169 ms |
36944 KB |
Output is correct |
40 |
Correct |
165 ms |
36580 KB |
Output is correct |
41 |
Correct |
174 ms |
35520 KB |
Output is correct |
42 |
Correct |
159 ms |
35508 KB |
Output is correct |
43 |
Correct |
186 ms |
35868 KB |
Output is correct |
44 |
Correct |
201 ms |
36000 KB |
Output is correct |
45 |
Correct |
192 ms |
35968 KB |
Output is correct |
46 |
Correct |
204 ms |
35916 KB |
Output is correct |
47 |
Correct |
204 ms |
36032 KB |
Output is correct |
48 |
Correct |
186 ms |
35876 KB |
Output is correct |
49 |
Correct |
183 ms |
35952 KB |
Output is correct |
50 |
Correct |
185 ms |
35936 KB |
Output is correct |
51 |
Correct |
178 ms |
35912 KB |
Output is correct |
52 |
Correct |
186 ms |
35960 KB |
Output is correct |
53 |
Correct |
4 ms |
9684 KB |
Output is correct |
54 |
Correct |
178 ms |
35968 KB |
Output is correct |
55 |
Correct |
202 ms |
36256 KB |
Output is correct |
56 |
Correct |
249 ms |
43668 KB |
Output is correct |
57 |
Correct |
303 ms |
47036 KB |
Output is correct |
58 |
Correct |
326 ms |
48488 KB |
Output is correct |
59 |
Correct |
288 ms |
48364 KB |
Output is correct |
60 |
Correct |
241 ms |
44584 KB |
Output is correct |
61 |
Correct |
289 ms |
47068 KB |
Output is correct |
62 |
Correct |
331 ms |
47152 KB |
Output is correct |
63 |
Correct |
206 ms |
36584 KB |
Output is correct |
64 |
Correct |
251 ms |
43900 KB |
Output is correct |
65 |
Correct |
320 ms |
47108 KB |
Output is correct |
66 |
Correct |
307 ms |
47704 KB |
Output is correct |
67 |
Correct |
312 ms |
47212 KB |
Output is correct |
68 |
Correct |
214 ms |
35616 KB |
Output is correct |
69 |
Correct |
266 ms |
44376 KB |
Output is correct |
70 |
Correct |
199 ms |
38444 KB |
Output is correct |
71 |
Correct |
176 ms |
37672 KB |
Output is correct |
72 |
Correct |
164 ms |
37572 KB |
Output is correct |
73 |
Correct |
178 ms |
36440 KB |
Output is correct |
74 |
Correct |
163 ms |
36892 KB |
Output is correct |
75 |
Correct |
203 ms |
36652 KB |
Output is correct |
76 |
Correct |
184 ms |
35536 KB |
Output is correct |
77 |
Correct |
165 ms |
35528 KB |
Output is correct |
78 |
Correct |
221 ms |
36664 KB |
Output is correct |
79 |
Correct |
377 ms |
46992 KB |
Output is correct |
80 |
Correct |
230 ms |
38956 KB |
Output is correct |
81 |
Correct |
323 ms |
44924 KB |
Output is correct |
82 |
Correct |
317 ms |
47188 KB |
Output is correct |
83 |
Correct |
401 ms |
47216 KB |
Output is correct |
84 |
Correct |
311 ms |
46536 KB |
Output is correct |
85 |
Correct |
191 ms |
35988 KB |
Output is correct |
86 |
Correct |
184 ms |
35900 KB |
Output is correct |
87 |
Correct |
159 ms |
35940 KB |
Output is correct |
88 |
Correct |
393 ms |
46460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9704 KB |
Output is correct |
2 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9704 KB |
Output is correct |
2 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
131 ms |
35516 KB |
Output is correct |
3 |
Correct |
113 ms |
35428 KB |
Output is correct |
4 |
Correct |
128 ms |
35472 KB |
Output is correct |
5 |
Correct |
128 ms |
35620 KB |
Output is correct |
6 |
Correct |
127 ms |
35520 KB |
Output is correct |
7 |
Correct |
125 ms |
35528 KB |
Output is correct |
8 |
Correct |
5 ms |
9720 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
194 ms |
35612 KB |
Output is correct |
11 |
Correct |
114 ms |
35520 KB |
Output is correct |
12 |
Correct |
106 ms |
35536 KB |
Output is correct |
13 |
Correct |
102 ms |
35524 KB |
Output is correct |
14 |
Correct |
144 ms |
35524 KB |
Output is correct |
15 |
Correct |
154 ms |
35500 KB |
Output is correct |
16 |
Correct |
164 ms |
35420 KB |
Output is correct |
17 |
Correct |
147 ms |
35520 KB |
Output is correct |
18 |
Correct |
6 ms |
9684 KB |
Output is correct |
19 |
Correct |
194 ms |
35448 KB |
Output is correct |
20 |
Correct |
195 ms |
35456 KB |
Output is correct |
21 |
Correct |
184 ms |
35640 KB |
Output is correct |
22 |
Correct |
189 ms |
35868 KB |
Output is correct |
23 |
Correct |
167 ms |
37296 KB |
Output is correct |
24 |
Correct |
184 ms |
37428 KB |
Output is correct |
25 |
Correct |
161 ms |
37088 KB |
Output is correct |
26 |
Correct |
194 ms |
37084 KB |
Output is correct |
27 |
Correct |
155 ms |
37076 KB |
Output is correct |
28 |
Correct |
186 ms |
35916 KB |
Output is correct |
29 |
Correct |
181 ms |
36280 KB |
Output is correct |
30 |
Correct |
177 ms |
36956 KB |
Output is correct |
31 |
Correct |
156 ms |
37084 KB |
Output is correct |
32 |
Correct |
183 ms |
36392 KB |
Output is correct |
33 |
Correct |
206 ms |
35520 KB |
Output is correct |
34 |
Correct |
180 ms |
35576 KB |
Output is correct |
35 |
Correct |
172 ms |
37404 KB |
Output is correct |
36 |
Correct |
162 ms |
37648 KB |
Output is correct |
37 |
Correct |
195 ms |
37612 KB |
Output is correct |
38 |
Correct |
166 ms |
36300 KB |
Output is correct |
39 |
Correct |
169 ms |
36944 KB |
Output is correct |
40 |
Correct |
165 ms |
36580 KB |
Output is correct |
41 |
Correct |
174 ms |
35520 KB |
Output is correct |
42 |
Correct |
159 ms |
35508 KB |
Output is correct |
43 |
Correct |
186 ms |
35868 KB |
Output is correct |
44 |
Correct |
201 ms |
36000 KB |
Output is correct |
45 |
Correct |
192 ms |
35968 KB |
Output is correct |
46 |
Correct |
204 ms |
35916 KB |
Output is correct |
47 |
Correct |
204 ms |
36032 KB |
Output is correct |
48 |
Correct |
186 ms |
35876 KB |
Output is correct |
49 |
Correct |
183 ms |
35952 KB |
Output is correct |
50 |
Correct |
185 ms |
35936 KB |
Output is correct |
51 |
Correct |
178 ms |
35912 KB |
Output is correct |
52 |
Correct |
186 ms |
35960 KB |
Output is correct |
53 |
Correct |
4 ms |
9684 KB |
Output is correct |
54 |
Correct |
178 ms |
35968 KB |
Output is correct |
55 |
Correct |
202 ms |
36256 KB |
Output is correct |
56 |
Correct |
249 ms |
43668 KB |
Output is correct |
57 |
Correct |
303 ms |
47036 KB |
Output is correct |
58 |
Correct |
326 ms |
48488 KB |
Output is correct |
59 |
Correct |
288 ms |
48364 KB |
Output is correct |
60 |
Correct |
241 ms |
44584 KB |
Output is correct |
61 |
Correct |
289 ms |
47068 KB |
Output is correct |
62 |
Correct |
331 ms |
47152 KB |
Output is correct |
63 |
Correct |
206 ms |
36584 KB |
Output is correct |
64 |
Correct |
251 ms |
43900 KB |
Output is correct |
65 |
Correct |
320 ms |
47108 KB |
Output is correct |
66 |
Correct |
307 ms |
47704 KB |
Output is correct |
67 |
Correct |
312 ms |
47212 KB |
Output is correct |
68 |
Correct |
214 ms |
35616 KB |
Output is correct |
69 |
Correct |
266 ms |
44376 KB |
Output is correct |
70 |
Correct |
199 ms |
38444 KB |
Output is correct |
71 |
Correct |
176 ms |
37672 KB |
Output is correct |
72 |
Correct |
164 ms |
37572 KB |
Output is correct |
73 |
Correct |
178 ms |
36440 KB |
Output is correct |
74 |
Correct |
163 ms |
36892 KB |
Output is correct |
75 |
Correct |
203 ms |
36652 KB |
Output is correct |
76 |
Correct |
184 ms |
35536 KB |
Output is correct |
77 |
Correct |
165 ms |
35528 KB |
Output is correct |
78 |
Correct |
221 ms |
36664 KB |
Output is correct |
79 |
Correct |
377 ms |
46992 KB |
Output is correct |
80 |
Correct |
230 ms |
38956 KB |
Output is correct |
81 |
Correct |
323 ms |
44924 KB |
Output is correct |
82 |
Correct |
317 ms |
47188 KB |
Output is correct |
83 |
Correct |
401 ms |
47216 KB |
Output is correct |
84 |
Correct |
311 ms |
46536 KB |
Output is correct |
85 |
Correct |
191 ms |
35988 KB |
Output is correct |
86 |
Correct |
184 ms |
35900 KB |
Output is correct |
87 |
Correct |
159 ms |
35940 KB |
Output is correct |
88 |
Correct |
393 ms |
46460 KB |
Output is correct |
89 |
Correct |
5 ms |
9704 KB |
Output is correct |
90 |
Incorrect |
4 ms |
9684 KB |
Output isn't correct |
91 |
Halted |
0 ms |
0 KB |
- |