# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796189 |
2023-07-28T07:40:23 Z |
이동현(#10071) |
Security Guard (JOI23_guard) |
C++17 |
|
204 ms |
19904 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;
const int NS = (int)2e5 + 4;
int n, m, q;
int a[NS], srt[NS], chk[NS];
vector<int> way[NS];
struct Dsu{
int n;
vector<int> pr;
Dsu(int m){
n = m + 4;
pr.resize(n);
iota(pr.begin(), pr.end(), 0);
}
int fd(int x){
return (x == pr[x] ? x : pr[x] = fd(pr[x]));
}
bool unite(int x, int y){
x = fd(x), y = fd(y);
if(x == y){
return false;
}
pr[y] = x;
return true;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> q;
int ans = 0;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
for(int i = 1; i <= m; ++i){
int x, y;
cin >> x >> y;
way[x].push_back(y);
way[y].push_back(x);
// ans += min(a[x], a[y]);
}
iota(srt, srt + NS, 0);
sort(srt + 1, srt + n + 1, [&](int x, int y){return a[x] < a[y];});
Dsu uni(n + 4);
int gr = 0;
for(int i = 1; i <= n; ++i){
int now = srt[i];
++gr;
chk[now] = 1;
sort(way[now].begin(), way[now].end(), [&](int x, int y){return a[x] < a[y];});
for(auto&nxt:way[now]){
if(chk[nxt]){
int rv = uni.unite(now, nxt);
gr -= rv;
if(rv) ans += a[nxt];
// cout << now << ' ' << nxt << endl;
}
}
// cout << now << ' ' << gr << endl;
if(i < n) ans += gr * (a[srt[i + 1]] - a[srt[i]]);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
66 ms |
17476 KB |
Output is correct |
3 |
Correct |
63 ms |
17472 KB |
Output is correct |
4 |
Correct |
72 ms |
17432 KB |
Output is correct |
5 |
Correct |
67 ms |
17484 KB |
Output is correct |
6 |
Correct |
67 ms |
17540 KB |
Output is correct |
7 |
Correct |
67 ms |
17440 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
66 ms |
17476 KB |
Output is correct |
3 |
Correct |
63 ms |
17472 KB |
Output is correct |
4 |
Correct |
72 ms |
17432 KB |
Output is correct |
5 |
Correct |
67 ms |
17484 KB |
Output is correct |
6 |
Correct |
67 ms |
17540 KB |
Output is correct |
7 |
Correct |
67 ms |
17440 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
3 ms |
6484 KB |
Output is correct |
10 |
Correct |
108 ms |
17472 KB |
Output is correct |
11 |
Correct |
73 ms |
17496 KB |
Output is correct |
12 |
Correct |
75 ms |
17468 KB |
Output is correct |
13 |
Correct |
73 ms |
17520 KB |
Output is correct |
14 |
Correct |
106 ms |
17508 KB |
Output is correct |
15 |
Correct |
105 ms |
17412 KB |
Output is correct |
16 |
Correct |
113 ms |
17528 KB |
Output is correct |
17 |
Correct |
104 ms |
17472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
66 ms |
17476 KB |
Output is correct |
3 |
Correct |
63 ms |
17472 KB |
Output is correct |
4 |
Correct |
72 ms |
17432 KB |
Output is correct |
5 |
Correct |
67 ms |
17484 KB |
Output is correct |
6 |
Correct |
67 ms |
17540 KB |
Output is correct |
7 |
Correct |
67 ms |
17440 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
3 ms |
6484 KB |
Output is correct |
10 |
Correct |
108 ms |
17472 KB |
Output is correct |
11 |
Correct |
73 ms |
17496 KB |
Output is correct |
12 |
Correct |
75 ms |
17468 KB |
Output is correct |
13 |
Correct |
73 ms |
17520 KB |
Output is correct |
14 |
Correct |
106 ms |
17508 KB |
Output is correct |
15 |
Correct |
105 ms |
17412 KB |
Output is correct |
16 |
Correct |
113 ms |
17528 KB |
Output is correct |
17 |
Correct |
104 ms |
17472 KB |
Output is correct |
18 |
Correct |
4 ms |
6484 KB |
Output is correct |
19 |
Correct |
160 ms |
18676 KB |
Output is correct |
20 |
Correct |
126 ms |
18620 KB |
Output is correct |
21 |
Correct |
197 ms |
18720 KB |
Output is correct |
22 |
Correct |
147 ms |
18868 KB |
Output is correct |
23 |
Correct |
132 ms |
19424 KB |
Output is correct |
24 |
Correct |
125 ms |
19672 KB |
Output is correct |
25 |
Correct |
204 ms |
19248 KB |
Output is correct |
26 |
Correct |
175 ms |
19160 KB |
Output is correct |
27 |
Correct |
189 ms |
19220 KB |
Output is correct |
28 |
Correct |
156 ms |
17932 KB |
Output is correct |
29 |
Correct |
172 ms |
18296 KB |
Output is correct |
30 |
Correct |
167 ms |
19048 KB |
Output is correct |
31 |
Correct |
146 ms |
19132 KB |
Output is correct |
32 |
Correct |
158 ms |
19268 KB |
Output is correct |
33 |
Correct |
118 ms |
19904 KB |
Output is correct |
34 |
Correct |
163 ms |
18680 KB |
Output is correct |
35 |
Correct |
137 ms |
19816 KB |
Output is correct |
36 |
Correct |
126 ms |
19688 KB |
Output is correct |
37 |
Correct |
144 ms |
19716 KB |
Output is correct |
38 |
Correct |
185 ms |
19464 KB |
Output is correct |
39 |
Correct |
145 ms |
19612 KB |
Output is correct |
40 |
Correct |
148 ms |
19308 KB |
Output is correct |
41 |
Correct |
175 ms |
17568 KB |
Output is correct |
42 |
Correct |
146 ms |
17524 KB |
Output is correct |
43 |
Correct |
155 ms |
18816 KB |
Output is correct |
44 |
Correct |
173 ms |
18884 KB |
Output is correct |
45 |
Correct |
135 ms |
18848 KB |
Output is correct |
46 |
Correct |
131 ms |
18864 KB |
Output is correct |
47 |
Correct |
142 ms |
18868 KB |
Output is correct |
48 |
Correct |
152 ms |
18824 KB |
Output is correct |
49 |
Correct |
179 ms |
18820 KB |
Output is correct |
50 |
Correct |
151 ms |
18824 KB |
Output is correct |
51 |
Correct |
127 ms |
18812 KB |
Output is correct |
52 |
Correct |
159 ms |
18768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
66 ms |
17476 KB |
Output is correct |
3 |
Correct |
63 ms |
17472 KB |
Output is correct |
4 |
Correct |
72 ms |
17432 KB |
Output is correct |
5 |
Correct |
67 ms |
17484 KB |
Output is correct |
6 |
Correct |
67 ms |
17540 KB |
Output is correct |
7 |
Correct |
67 ms |
17440 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
3 ms |
6484 KB |
Output is correct |
10 |
Correct |
108 ms |
17472 KB |
Output is correct |
11 |
Correct |
73 ms |
17496 KB |
Output is correct |
12 |
Correct |
75 ms |
17468 KB |
Output is correct |
13 |
Correct |
73 ms |
17520 KB |
Output is correct |
14 |
Correct |
106 ms |
17508 KB |
Output is correct |
15 |
Correct |
105 ms |
17412 KB |
Output is correct |
16 |
Correct |
113 ms |
17528 KB |
Output is correct |
17 |
Correct |
104 ms |
17472 KB |
Output is correct |
18 |
Correct |
4 ms |
6484 KB |
Output is correct |
19 |
Correct |
160 ms |
18676 KB |
Output is correct |
20 |
Correct |
126 ms |
18620 KB |
Output is correct |
21 |
Correct |
197 ms |
18720 KB |
Output is correct |
22 |
Correct |
147 ms |
18868 KB |
Output is correct |
23 |
Correct |
132 ms |
19424 KB |
Output is correct |
24 |
Correct |
125 ms |
19672 KB |
Output is correct |
25 |
Correct |
204 ms |
19248 KB |
Output is correct |
26 |
Correct |
175 ms |
19160 KB |
Output is correct |
27 |
Correct |
189 ms |
19220 KB |
Output is correct |
28 |
Correct |
156 ms |
17932 KB |
Output is correct |
29 |
Correct |
172 ms |
18296 KB |
Output is correct |
30 |
Correct |
167 ms |
19048 KB |
Output is correct |
31 |
Correct |
146 ms |
19132 KB |
Output is correct |
32 |
Correct |
158 ms |
19268 KB |
Output is correct |
33 |
Correct |
118 ms |
19904 KB |
Output is correct |
34 |
Correct |
163 ms |
18680 KB |
Output is correct |
35 |
Correct |
137 ms |
19816 KB |
Output is correct |
36 |
Correct |
126 ms |
19688 KB |
Output is correct |
37 |
Correct |
144 ms |
19716 KB |
Output is correct |
38 |
Correct |
185 ms |
19464 KB |
Output is correct |
39 |
Correct |
145 ms |
19612 KB |
Output is correct |
40 |
Correct |
148 ms |
19308 KB |
Output is correct |
41 |
Correct |
175 ms |
17568 KB |
Output is correct |
42 |
Correct |
146 ms |
17524 KB |
Output is correct |
43 |
Correct |
155 ms |
18816 KB |
Output is correct |
44 |
Correct |
173 ms |
18884 KB |
Output is correct |
45 |
Correct |
135 ms |
18848 KB |
Output is correct |
46 |
Correct |
131 ms |
18864 KB |
Output is correct |
47 |
Correct |
142 ms |
18868 KB |
Output is correct |
48 |
Correct |
152 ms |
18824 KB |
Output is correct |
49 |
Correct |
179 ms |
18820 KB |
Output is correct |
50 |
Correct |
151 ms |
18824 KB |
Output is correct |
51 |
Correct |
127 ms |
18812 KB |
Output is correct |
52 |
Correct |
159 ms |
18768 KB |
Output is correct |
53 |
Correct |
3 ms |
6484 KB |
Output is correct |
54 |
Incorrect |
134 ms |
18764 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Incorrect |
4 ms |
6484 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Incorrect |
4 ms |
6484 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
66 ms |
17476 KB |
Output is correct |
3 |
Correct |
63 ms |
17472 KB |
Output is correct |
4 |
Correct |
72 ms |
17432 KB |
Output is correct |
5 |
Correct |
67 ms |
17484 KB |
Output is correct |
6 |
Correct |
67 ms |
17540 KB |
Output is correct |
7 |
Correct |
67 ms |
17440 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
3 ms |
6484 KB |
Output is correct |
10 |
Correct |
108 ms |
17472 KB |
Output is correct |
11 |
Correct |
73 ms |
17496 KB |
Output is correct |
12 |
Correct |
75 ms |
17468 KB |
Output is correct |
13 |
Correct |
73 ms |
17520 KB |
Output is correct |
14 |
Correct |
106 ms |
17508 KB |
Output is correct |
15 |
Correct |
105 ms |
17412 KB |
Output is correct |
16 |
Correct |
113 ms |
17528 KB |
Output is correct |
17 |
Correct |
104 ms |
17472 KB |
Output is correct |
18 |
Correct |
4 ms |
6484 KB |
Output is correct |
19 |
Correct |
160 ms |
18676 KB |
Output is correct |
20 |
Correct |
126 ms |
18620 KB |
Output is correct |
21 |
Correct |
197 ms |
18720 KB |
Output is correct |
22 |
Correct |
147 ms |
18868 KB |
Output is correct |
23 |
Correct |
132 ms |
19424 KB |
Output is correct |
24 |
Correct |
125 ms |
19672 KB |
Output is correct |
25 |
Correct |
204 ms |
19248 KB |
Output is correct |
26 |
Correct |
175 ms |
19160 KB |
Output is correct |
27 |
Correct |
189 ms |
19220 KB |
Output is correct |
28 |
Correct |
156 ms |
17932 KB |
Output is correct |
29 |
Correct |
172 ms |
18296 KB |
Output is correct |
30 |
Correct |
167 ms |
19048 KB |
Output is correct |
31 |
Correct |
146 ms |
19132 KB |
Output is correct |
32 |
Correct |
158 ms |
19268 KB |
Output is correct |
33 |
Correct |
118 ms |
19904 KB |
Output is correct |
34 |
Correct |
163 ms |
18680 KB |
Output is correct |
35 |
Correct |
137 ms |
19816 KB |
Output is correct |
36 |
Correct |
126 ms |
19688 KB |
Output is correct |
37 |
Correct |
144 ms |
19716 KB |
Output is correct |
38 |
Correct |
185 ms |
19464 KB |
Output is correct |
39 |
Correct |
145 ms |
19612 KB |
Output is correct |
40 |
Correct |
148 ms |
19308 KB |
Output is correct |
41 |
Correct |
175 ms |
17568 KB |
Output is correct |
42 |
Correct |
146 ms |
17524 KB |
Output is correct |
43 |
Correct |
155 ms |
18816 KB |
Output is correct |
44 |
Correct |
173 ms |
18884 KB |
Output is correct |
45 |
Correct |
135 ms |
18848 KB |
Output is correct |
46 |
Correct |
131 ms |
18864 KB |
Output is correct |
47 |
Correct |
142 ms |
18868 KB |
Output is correct |
48 |
Correct |
152 ms |
18824 KB |
Output is correct |
49 |
Correct |
179 ms |
18820 KB |
Output is correct |
50 |
Correct |
151 ms |
18824 KB |
Output is correct |
51 |
Correct |
127 ms |
18812 KB |
Output is correct |
52 |
Correct |
159 ms |
18768 KB |
Output is correct |
53 |
Correct |
3 ms |
6484 KB |
Output is correct |
54 |
Incorrect |
134 ms |
18764 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |