# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796132 |
2023-07-28T06:47:39 Z |
박상훈(#10069) |
Security Guard (JOI23_guard) |
C++17 |
|
395 ms |
48512 KB |
#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());
for (auto &[z, x, y]:E) if (dsu.merge(x, y)){
G[x].push_back(y);
G[y].push_back(x);
}
ans = 0;
for (auto &x:G[root]) dfs(x, root);
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);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
132 ms |
44348 KB |
Output is correct |
3 |
Correct |
128 ms |
44440 KB |
Output is correct |
4 |
Correct |
141 ms |
44376 KB |
Output is correct |
5 |
Correct |
138 ms |
44300 KB |
Output is correct |
6 |
Correct |
147 ms |
44328 KB |
Output is correct |
7 |
Correct |
139 ms |
44272 KB |
Output is correct |
8 |
Correct |
4 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
132 ms |
44348 KB |
Output is correct |
3 |
Correct |
128 ms |
44440 KB |
Output is correct |
4 |
Correct |
141 ms |
44376 KB |
Output is correct |
5 |
Correct |
138 ms |
44300 KB |
Output is correct |
6 |
Correct |
147 ms |
44328 KB |
Output is correct |
7 |
Correct |
139 ms |
44272 KB |
Output is correct |
8 |
Correct |
4 ms |
9684 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
177 ms |
40884 KB |
Output is correct |
11 |
Correct |
127 ms |
44432 KB |
Output is correct |
12 |
Correct |
125 ms |
44452 KB |
Output is correct |
13 |
Correct |
122 ms |
44592 KB |
Output is correct |
14 |
Correct |
163 ms |
44456 KB |
Output is correct |
15 |
Correct |
187 ms |
44444 KB |
Output is correct |
16 |
Correct |
177 ms |
43328 KB |
Output is correct |
17 |
Correct |
165 ms |
43780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
132 ms |
44348 KB |
Output is correct |
3 |
Correct |
128 ms |
44440 KB |
Output is correct |
4 |
Correct |
141 ms |
44376 KB |
Output is correct |
5 |
Correct |
138 ms |
44300 KB |
Output is correct |
6 |
Correct |
147 ms |
44328 KB |
Output is correct |
7 |
Correct |
139 ms |
44272 KB |
Output is correct |
8 |
Correct |
4 ms |
9684 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
177 ms |
40884 KB |
Output is correct |
11 |
Correct |
127 ms |
44432 KB |
Output is correct |
12 |
Correct |
125 ms |
44452 KB |
Output is correct |
13 |
Correct |
122 ms |
44592 KB |
Output is correct |
14 |
Correct |
163 ms |
44456 KB |
Output is correct |
15 |
Correct |
187 ms |
44444 KB |
Output is correct |
16 |
Correct |
177 ms |
43328 KB |
Output is correct |
17 |
Correct |
165 ms |
43780 KB |
Output is correct |
18 |
Correct |
4 ms |
9684 KB |
Output is correct |
19 |
Correct |
247 ms |
39532 KB |
Output is correct |
20 |
Correct |
232 ms |
38908 KB |
Output is correct |
21 |
Correct |
210 ms |
35044 KB |
Output is correct |
22 |
Correct |
208 ms |
35420 KB |
Output is correct |
23 |
Correct |
178 ms |
36912 KB |
Output is correct |
24 |
Correct |
177 ms |
36932 KB |
Output is correct |
25 |
Correct |
175 ms |
36636 KB |
Output is correct |
26 |
Correct |
170 ms |
36588 KB |
Output is correct |
27 |
Correct |
165 ms |
36768 KB |
Output is correct |
28 |
Correct |
239 ms |
42932 KB |
Output is correct |
29 |
Correct |
203 ms |
39200 KB |
Output is correct |
30 |
Correct |
185 ms |
37900 KB |
Output is correct |
31 |
Correct |
163 ms |
36660 KB |
Output is correct |
32 |
Correct |
217 ms |
35988 KB |
Output is correct |
33 |
Correct |
208 ms |
34848 KB |
Output is correct |
34 |
Correct |
191 ms |
35192 KB |
Output is correct |
35 |
Correct |
195 ms |
36916 KB |
Output is correct |
36 |
Correct |
198 ms |
36940 KB |
Output is correct |
37 |
Correct |
167 ms |
37052 KB |
Output is correct |
38 |
Correct |
197 ms |
38876 KB |
Output is correct |
39 |
Correct |
172 ms |
40460 KB |
Output is correct |
40 |
Correct |
175 ms |
37484 KB |
Output is correct |
41 |
Correct |
230 ms |
44496 KB |
Output is correct |
42 |
Correct |
172 ms |
44188 KB |
Output is correct |
43 |
Correct |
188 ms |
35164 KB |
Output is correct |
44 |
Correct |
236 ms |
35412 KB |
Output is correct |
45 |
Correct |
197 ms |
35436 KB |
Output is correct |
46 |
Correct |
202 ms |
35352 KB |
Output is correct |
47 |
Correct |
224 ms |
35524 KB |
Output is correct |
48 |
Correct |
200 ms |
35420 KB |
Output is correct |
49 |
Correct |
182 ms |
35416 KB |
Output is correct |
50 |
Correct |
200 ms |
35448 KB |
Output is correct |
51 |
Correct |
197 ms |
35524 KB |
Output is correct |
52 |
Correct |
188 ms |
35416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
132 ms |
44348 KB |
Output is correct |
3 |
Correct |
128 ms |
44440 KB |
Output is correct |
4 |
Correct |
141 ms |
44376 KB |
Output is correct |
5 |
Correct |
138 ms |
44300 KB |
Output is correct |
6 |
Correct |
147 ms |
44328 KB |
Output is correct |
7 |
Correct |
139 ms |
44272 KB |
Output is correct |
8 |
Correct |
4 ms |
9684 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
177 ms |
40884 KB |
Output is correct |
11 |
Correct |
127 ms |
44432 KB |
Output is correct |
12 |
Correct |
125 ms |
44452 KB |
Output is correct |
13 |
Correct |
122 ms |
44592 KB |
Output is correct |
14 |
Correct |
163 ms |
44456 KB |
Output is correct |
15 |
Correct |
187 ms |
44444 KB |
Output is correct |
16 |
Correct |
177 ms |
43328 KB |
Output is correct |
17 |
Correct |
165 ms |
43780 KB |
Output is correct |
18 |
Correct |
4 ms |
9684 KB |
Output is correct |
19 |
Correct |
247 ms |
39532 KB |
Output is correct |
20 |
Correct |
232 ms |
38908 KB |
Output is correct |
21 |
Correct |
210 ms |
35044 KB |
Output is correct |
22 |
Correct |
208 ms |
35420 KB |
Output is correct |
23 |
Correct |
178 ms |
36912 KB |
Output is correct |
24 |
Correct |
177 ms |
36932 KB |
Output is correct |
25 |
Correct |
175 ms |
36636 KB |
Output is correct |
26 |
Correct |
170 ms |
36588 KB |
Output is correct |
27 |
Correct |
165 ms |
36768 KB |
Output is correct |
28 |
Correct |
239 ms |
42932 KB |
Output is correct |
29 |
Correct |
203 ms |
39200 KB |
Output is correct |
30 |
Correct |
185 ms |
37900 KB |
Output is correct |
31 |
Correct |
163 ms |
36660 KB |
Output is correct |
32 |
Correct |
217 ms |
35988 KB |
Output is correct |
33 |
Correct |
208 ms |
34848 KB |
Output is correct |
34 |
Correct |
191 ms |
35192 KB |
Output is correct |
35 |
Correct |
195 ms |
36916 KB |
Output is correct |
36 |
Correct |
198 ms |
36940 KB |
Output is correct |
37 |
Correct |
167 ms |
37052 KB |
Output is correct |
38 |
Correct |
197 ms |
38876 KB |
Output is correct |
39 |
Correct |
172 ms |
40460 KB |
Output is correct |
40 |
Correct |
175 ms |
37484 KB |
Output is correct |
41 |
Correct |
230 ms |
44496 KB |
Output is correct |
42 |
Correct |
172 ms |
44188 KB |
Output is correct |
43 |
Correct |
188 ms |
35164 KB |
Output is correct |
44 |
Correct |
236 ms |
35412 KB |
Output is correct |
45 |
Correct |
197 ms |
35436 KB |
Output is correct |
46 |
Correct |
202 ms |
35352 KB |
Output is correct |
47 |
Correct |
224 ms |
35524 KB |
Output is correct |
48 |
Correct |
200 ms |
35420 KB |
Output is correct |
49 |
Correct |
182 ms |
35416 KB |
Output is correct |
50 |
Correct |
200 ms |
35448 KB |
Output is correct |
51 |
Correct |
197 ms |
35524 KB |
Output is correct |
52 |
Correct |
188 ms |
35416 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
224 ms |
40224 KB |
Output is correct |
55 |
Correct |
218 ms |
39420 KB |
Output is correct |
56 |
Correct |
247 ms |
44104 KB |
Output is correct |
57 |
Correct |
323 ms |
46812 KB |
Output is correct |
58 |
Correct |
313 ms |
48208 KB |
Output is correct |
59 |
Correct |
305 ms |
48088 KB |
Output is correct |
60 |
Correct |
224 ms |
44924 KB |
Output is correct |
61 |
Correct |
292 ms |
46944 KB |
Output is correct |
62 |
Correct |
330 ms |
46936 KB |
Output is correct |
63 |
Correct |
232 ms |
43528 KB |
Output is correct |
64 |
Correct |
288 ms |
45536 KB |
Output is correct |
65 |
Correct |
315 ms |
48512 KB |
Output is correct |
66 |
Correct |
321 ms |
47468 KB |
Output is correct |
67 |
Correct |
383 ms |
46948 KB |
Output is correct |
68 |
Correct |
188 ms |
35048 KB |
Output is correct |
69 |
Correct |
331 ms |
44792 KB |
Output is correct |
70 |
Correct |
209 ms |
38024 KB |
Output is correct |
71 |
Correct |
207 ms |
37228 KB |
Output is correct |
72 |
Correct |
192 ms |
37156 KB |
Output is correct |
73 |
Correct |
204 ms |
38760 KB |
Output is correct |
74 |
Correct |
175 ms |
40444 KB |
Output is correct |
75 |
Correct |
189 ms |
37616 KB |
Output is correct |
76 |
Correct |
185 ms |
44344 KB |
Output is correct |
77 |
Correct |
199 ms |
44368 KB |
Output is correct |
78 |
Correct |
256 ms |
36184 KB |
Output is correct |
79 |
Correct |
334 ms |
46820 KB |
Output is correct |
80 |
Correct |
255 ms |
38636 KB |
Output is correct |
81 |
Correct |
323 ms |
45224 KB |
Output is correct |
82 |
Correct |
395 ms |
46864 KB |
Output is correct |
83 |
Correct |
360 ms |
46924 KB |
Output is correct |
84 |
Correct |
354 ms |
46268 KB |
Output is correct |
85 |
Correct |
186 ms |
35412 KB |
Output is correct |
86 |
Correct |
187 ms |
35496 KB |
Output is correct |
87 |
Correct |
172 ms |
35364 KB |
Output is correct |
88 |
Correct |
368 ms |
46188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
132 ms |
44348 KB |
Output is correct |
3 |
Correct |
128 ms |
44440 KB |
Output is correct |
4 |
Correct |
141 ms |
44376 KB |
Output is correct |
5 |
Correct |
138 ms |
44300 KB |
Output is correct |
6 |
Correct |
147 ms |
44328 KB |
Output is correct |
7 |
Correct |
139 ms |
44272 KB |
Output is correct |
8 |
Correct |
4 ms |
9684 KB |
Output is correct |
9 |
Correct |
4 ms |
9684 KB |
Output is correct |
10 |
Correct |
177 ms |
40884 KB |
Output is correct |
11 |
Correct |
127 ms |
44432 KB |
Output is correct |
12 |
Correct |
125 ms |
44452 KB |
Output is correct |
13 |
Correct |
122 ms |
44592 KB |
Output is correct |
14 |
Correct |
163 ms |
44456 KB |
Output is correct |
15 |
Correct |
187 ms |
44444 KB |
Output is correct |
16 |
Correct |
177 ms |
43328 KB |
Output is correct |
17 |
Correct |
165 ms |
43780 KB |
Output is correct |
18 |
Correct |
4 ms |
9684 KB |
Output is correct |
19 |
Correct |
247 ms |
39532 KB |
Output is correct |
20 |
Correct |
232 ms |
38908 KB |
Output is correct |
21 |
Correct |
210 ms |
35044 KB |
Output is correct |
22 |
Correct |
208 ms |
35420 KB |
Output is correct |
23 |
Correct |
178 ms |
36912 KB |
Output is correct |
24 |
Correct |
177 ms |
36932 KB |
Output is correct |
25 |
Correct |
175 ms |
36636 KB |
Output is correct |
26 |
Correct |
170 ms |
36588 KB |
Output is correct |
27 |
Correct |
165 ms |
36768 KB |
Output is correct |
28 |
Correct |
239 ms |
42932 KB |
Output is correct |
29 |
Correct |
203 ms |
39200 KB |
Output is correct |
30 |
Correct |
185 ms |
37900 KB |
Output is correct |
31 |
Correct |
163 ms |
36660 KB |
Output is correct |
32 |
Correct |
217 ms |
35988 KB |
Output is correct |
33 |
Correct |
208 ms |
34848 KB |
Output is correct |
34 |
Correct |
191 ms |
35192 KB |
Output is correct |
35 |
Correct |
195 ms |
36916 KB |
Output is correct |
36 |
Correct |
198 ms |
36940 KB |
Output is correct |
37 |
Correct |
167 ms |
37052 KB |
Output is correct |
38 |
Correct |
197 ms |
38876 KB |
Output is correct |
39 |
Correct |
172 ms |
40460 KB |
Output is correct |
40 |
Correct |
175 ms |
37484 KB |
Output is correct |
41 |
Correct |
230 ms |
44496 KB |
Output is correct |
42 |
Correct |
172 ms |
44188 KB |
Output is correct |
43 |
Correct |
188 ms |
35164 KB |
Output is correct |
44 |
Correct |
236 ms |
35412 KB |
Output is correct |
45 |
Correct |
197 ms |
35436 KB |
Output is correct |
46 |
Correct |
202 ms |
35352 KB |
Output is correct |
47 |
Correct |
224 ms |
35524 KB |
Output is correct |
48 |
Correct |
200 ms |
35420 KB |
Output is correct |
49 |
Correct |
182 ms |
35416 KB |
Output is correct |
50 |
Correct |
200 ms |
35448 KB |
Output is correct |
51 |
Correct |
197 ms |
35524 KB |
Output is correct |
52 |
Correct |
188 ms |
35416 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
224 ms |
40224 KB |
Output is correct |
55 |
Correct |
218 ms |
39420 KB |
Output is correct |
56 |
Correct |
247 ms |
44104 KB |
Output is correct |
57 |
Correct |
323 ms |
46812 KB |
Output is correct |
58 |
Correct |
313 ms |
48208 KB |
Output is correct |
59 |
Correct |
305 ms |
48088 KB |
Output is correct |
60 |
Correct |
224 ms |
44924 KB |
Output is correct |
61 |
Correct |
292 ms |
46944 KB |
Output is correct |
62 |
Correct |
330 ms |
46936 KB |
Output is correct |
63 |
Correct |
232 ms |
43528 KB |
Output is correct |
64 |
Correct |
288 ms |
45536 KB |
Output is correct |
65 |
Correct |
315 ms |
48512 KB |
Output is correct |
66 |
Correct |
321 ms |
47468 KB |
Output is correct |
67 |
Correct |
383 ms |
46948 KB |
Output is correct |
68 |
Correct |
188 ms |
35048 KB |
Output is correct |
69 |
Correct |
331 ms |
44792 KB |
Output is correct |
70 |
Correct |
209 ms |
38024 KB |
Output is correct |
71 |
Correct |
207 ms |
37228 KB |
Output is correct |
72 |
Correct |
192 ms |
37156 KB |
Output is correct |
73 |
Correct |
204 ms |
38760 KB |
Output is correct |
74 |
Correct |
175 ms |
40444 KB |
Output is correct |
75 |
Correct |
189 ms |
37616 KB |
Output is correct |
76 |
Correct |
185 ms |
44344 KB |
Output is correct |
77 |
Correct |
199 ms |
44368 KB |
Output is correct |
78 |
Correct |
256 ms |
36184 KB |
Output is correct |
79 |
Correct |
334 ms |
46820 KB |
Output is correct |
80 |
Correct |
255 ms |
38636 KB |
Output is correct |
81 |
Correct |
323 ms |
45224 KB |
Output is correct |
82 |
Correct |
395 ms |
46864 KB |
Output is correct |
83 |
Correct |
360 ms |
46924 KB |
Output is correct |
84 |
Correct |
354 ms |
46268 KB |
Output is correct |
85 |
Correct |
186 ms |
35412 KB |
Output is correct |
86 |
Correct |
187 ms |
35496 KB |
Output is correct |
87 |
Correct |
172 ms |
35364 KB |
Output is correct |
88 |
Correct |
368 ms |
46188 KB |
Output is correct |
89 |
Correct |
5 ms |
9684 KB |
Output is correct |
90 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
91 |
Halted |
0 ms |
0 KB |
- |