# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796185 |
2023-07-28T07:34:35 Z |
이동현(#10071) |
Security Guard (JOI23_guard) |
C++17 |
|
165 ms |
19800 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;
for(auto&nxt:way[now]){
if(chk[nxt]){
int rv = uni.unite(now, nxt);
gr -= rv;
if(rv) ans += min(a[now], 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 |
6612 KB |
Output is correct |
2 |
Correct |
62 ms |
17480 KB |
Output is correct |
3 |
Correct |
58 ms |
17444 KB |
Output is correct |
4 |
Correct |
64 ms |
17480 KB |
Output is correct |
5 |
Correct |
66 ms |
17476 KB |
Output is correct |
6 |
Correct |
84 ms |
17420 KB |
Output is correct |
7 |
Correct |
66 ms |
17508 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6612 KB |
Output is correct |
2 |
Correct |
62 ms |
17480 KB |
Output is correct |
3 |
Correct |
58 ms |
17444 KB |
Output is correct |
4 |
Correct |
64 ms |
17480 KB |
Output is correct |
5 |
Correct |
66 ms |
17476 KB |
Output is correct |
6 |
Correct |
84 ms |
17420 KB |
Output is correct |
7 |
Correct |
66 ms |
17508 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
122 ms |
17476 KB |
Output is correct |
11 |
Correct |
72 ms |
17440 KB |
Output is correct |
12 |
Correct |
67 ms |
17480 KB |
Output is correct |
13 |
Correct |
67 ms |
17476 KB |
Output is correct |
14 |
Correct |
124 ms |
17508 KB |
Output is correct |
15 |
Correct |
106 ms |
17456 KB |
Output is correct |
16 |
Correct |
103 ms |
17544 KB |
Output is correct |
17 |
Correct |
102 ms |
17424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6612 KB |
Output is correct |
2 |
Correct |
62 ms |
17480 KB |
Output is correct |
3 |
Correct |
58 ms |
17444 KB |
Output is correct |
4 |
Correct |
64 ms |
17480 KB |
Output is correct |
5 |
Correct |
66 ms |
17476 KB |
Output is correct |
6 |
Correct |
84 ms |
17420 KB |
Output is correct |
7 |
Correct |
66 ms |
17508 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
122 ms |
17476 KB |
Output is correct |
11 |
Correct |
72 ms |
17440 KB |
Output is correct |
12 |
Correct |
67 ms |
17480 KB |
Output is correct |
13 |
Correct |
67 ms |
17476 KB |
Output is correct |
14 |
Correct |
124 ms |
17508 KB |
Output is correct |
15 |
Correct |
106 ms |
17456 KB |
Output is correct |
16 |
Correct |
103 ms |
17544 KB |
Output is correct |
17 |
Correct |
102 ms |
17424 KB |
Output is correct |
18 |
Correct |
3 ms |
6484 KB |
Output is correct |
19 |
Correct |
152 ms |
18520 KB |
Output is correct |
20 |
Correct |
136 ms |
18556 KB |
Output is correct |
21 |
Correct |
130 ms |
18452 KB |
Output is correct |
22 |
Correct |
149 ms |
18720 KB |
Output is correct |
23 |
Correct |
105 ms |
19260 KB |
Output is correct |
24 |
Correct |
109 ms |
19532 KB |
Output is correct |
25 |
Correct |
109 ms |
19080 KB |
Output is correct |
26 |
Correct |
102 ms |
19020 KB |
Output is correct |
27 |
Correct |
96 ms |
19060 KB |
Output is correct |
28 |
Correct |
121 ms |
17856 KB |
Output is correct |
29 |
Correct |
139 ms |
18232 KB |
Output is correct |
30 |
Correct |
143 ms |
18936 KB |
Output is correct |
31 |
Correct |
115 ms |
19020 KB |
Output is correct |
32 |
Correct |
137 ms |
19064 KB |
Output is correct |
33 |
Correct |
115 ms |
19800 KB |
Output is correct |
34 |
Correct |
116 ms |
18612 KB |
Output is correct |
35 |
Correct |
163 ms |
19648 KB |
Output is correct |
36 |
Correct |
94 ms |
19596 KB |
Output is correct |
37 |
Correct |
104 ms |
19580 KB |
Output is correct |
38 |
Correct |
119 ms |
19432 KB |
Output is correct |
39 |
Correct |
100 ms |
19424 KB |
Output is correct |
40 |
Correct |
122 ms |
19272 KB |
Output is correct |
41 |
Correct |
146 ms |
17520 KB |
Output is correct |
42 |
Correct |
136 ms |
17460 KB |
Output is correct |
43 |
Correct |
140 ms |
18684 KB |
Output is correct |
44 |
Correct |
122 ms |
18636 KB |
Output is correct |
45 |
Correct |
110 ms |
18692 KB |
Output is correct |
46 |
Correct |
120 ms |
18696 KB |
Output is correct |
47 |
Correct |
130 ms |
18704 KB |
Output is correct |
48 |
Correct |
140 ms |
18700 KB |
Output is correct |
49 |
Correct |
137 ms |
18696 KB |
Output is correct |
50 |
Correct |
117 ms |
18732 KB |
Output is correct |
51 |
Correct |
96 ms |
18688 KB |
Output is correct |
52 |
Correct |
103 ms |
18704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6612 KB |
Output is correct |
2 |
Correct |
62 ms |
17480 KB |
Output is correct |
3 |
Correct |
58 ms |
17444 KB |
Output is correct |
4 |
Correct |
64 ms |
17480 KB |
Output is correct |
5 |
Correct |
66 ms |
17476 KB |
Output is correct |
6 |
Correct |
84 ms |
17420 KB |
Output is correct |
7 |
Correct |
66 ms |
17508 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
122 ms |
17476 KB |
Output is correct |
11 |
Correct |
72 ms |
17440 KB |
Output is correct |
12 |
Correct |
67 ms |
17480 KB |
Output is correct |
13 |
Correct |
67 ms |
17476 KB |
Output is correct |
14 |
Correct |
124 ms |
17508 KB |
Output is correct |
15 |
Correct |
106 ms |
17456 KB |
Output is correct |
16 |
Correct |
103 ms |
17544 KB |
Output is correct |
17 |
Correct |
102 ms |
17424 KB |
Output is correct |
18 |
Correct |
3 ms |
6484 KB |
Output is correct |
19 |
Correct |
152 ms |
18520 KB |
Output is correct |
20 |
Correct |
136 ms |
18556 KB |
Output is correct |
21 |
Correct |
130 ms |
18452 KB |
Output is correct |
22 |
Correct |
149 ms |
18720 KB |
Output is correct |
23 |
Correct |
105 ms |
19260 KB |
Output is correct |
24 |
Correct |
109 ms |
19532 KB |
Output is correct |
25 |
Correct |
109 ms |
19080 KB |
Output is correct |
26 |
Correct |
102 ms |
19020 KB |
Output is correct |
27 |
Correct |
96 ms |
19060 KB |
Output is correct |
28 |
Correct |
121 ms |
17856 KB |
Output is correct |
29 |
Correct |
139 ms |
18232 KB |
Output is correct |
30 |
Correct |
143 ms |
18936 KB |
Output is correct |
31 |
Correct |
115 ms |
19020 KB |
Output is correct |
32 |
Correct |
137 ms |
19064 KB |
Output is correct |
33 |
Correct |
115 ms |
19800 KB |
Output is correct |
34 |
Correct |
116 ms |
18612 KB |
Output is correct |
35 |
Correct |
163 ms |
19648 KB |
Output is correct |
36 |
Correct |
94 ms |
19596 KB |
Output is correct |
37 |
Correct |
104 ms |
19580 KB |
Output is correct |
38 |
Correct |
119 ms |
19432 KB |
Output is correct |
39 |
Correct |
100 ms |
19424 KB |
Output is correct |
40 |
Correct |
122 ms |
19272 KB |
Output is correct |
41 |
Correct |
146 ms |
17520 KB |
Output is correct |
42 |
Correct |
136 ms |
17460 KB |
Output is correct |
43 |
Correct |
140 ms |
18684 KB |
Output is correct |
44 |
Correct |
122 ms |
18636 KB |
Output is correct |
45 |
Correct |
110 ms |
18692 KB |
Output is correct |
46 |
Correct |
120 ms |
18696 KB |
Output is correct |
47 |
Correct |
130 ms |
18704 KB |
Output is correct |
48 |
Correct |
140 ms |
18700 KB |
Output is correct |
49 |
Correct |
137 ms |
18696 KB |
Output is correct |
50 |
Correct |
117 ms |
18732 KB |
Output is correct |
51 |
Correct |
96 ms |
18688 KB |
Output is correct |
52 |
Correct |
103 ms |
18704 KB |
Output is correct |
53 |
Correct |
3 ms |
6484 KB |
Output is correct |
54 |
Incorrect |
165 ms |
18776 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 |
3 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 |
3 ms |
6484 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6612 KB |
Output is correct |
2 |
Correct |
62 ms |
17480 KB |
Output is correct |
3 |
Correct |
58 ms |
17444 KB |
Output is correct |
4 |
Correct |
64 ms |
17480 KB |
Output is correct |
5 |
Correct |
66 ms |
17476 KB |
Output is correct |
6 |
Correct |
84 ms |
17420 KB |
Output is correct |
7 |
Correct |
66 ms |
17508 KB |
Output is correct |
8 |
Correct |
3 ms |
6484 KB |
Output is correct |
9 |
Correct |
4 ms |
6484 KB |
Output is correct |
10 |
Correct |
122 ms |
17476 KB |
Output is correct |
11 |
Correct |
72 ms |
17440 KB |
Output is correct |
12 |
Correct |
67 ms |
17480 KB |
Output is correct |
13 |
Correct |
67 ms |
17476 KB |
Output is correct |
14 |
Correct |
124 ms |
17508 KB |
Output is correct |
15 |
Correct |
106 ms |
17456 KB |
Output is correct |
16 |
Correct |
103 ms |
17544 KB |
Output is correct |
17 |
Correct |
102 ms |
17424 KB |
Output is correct |
18 |
Correct |
3 ms |
6484 KB |
Output is correct |
19 |
Correct |
152 ms |
18520 KB |
Output is correct |
20 |
Correct |
136 ms |
18556 KB |
Output is correct |
21 |
Correct |
130 ms |
18452 KB |
Output is correct |
22 |
Correct |
149 ms |
18720 KB |
Output is correct |
23 |
Correct |
105 ms |
19260 KB |
Output is correct |
24 |
Correct |
109 ms |
19532 KB |
Output is correct |
25 |
Correct |
109 ms |
19080 KB |
Output is correct |
26 |
Correct |
102 ms |
19020 KB |
Output is correct |
27 |
Correct |
96 ms |
19060 KB |
Output is correct |
28 |
Correct |
121 ms |
17856 KB |
Output is correct |
29 |
Correct |
139 ms |
18232 KB |
Output is correct |
30 |
Correct |
143 ms |
18936 KB |
Output is correct |
31 |
Correct |
115 ms |
19020 KB |
Output is correct |
32 |
Correct |
137 ms |
19064 KB |
Output is correct |
33 |
Correct |
115 ms |
19800 KB |
Output is correct |
34 |
Correct |
116 ms |
18612 KB |
Output is correct |
35 |
Correct |
163 ms |
19648 KB |
Output is correct |
36 |
Correct |
94 ms |
19596 KB |
Output is correct |
37 |
Correct |
104 ms |
19580 KB |
Output is correct |
38 |
Correct |
119 ms |
19432 KB |
Output is correct |
39 |
Correct |
100 ms |
19424 KB |
Output is correct |
40 |
Correct |
122 ms |
19272 KB |
Output is correct |
41 |
Correct |
146 ms |
17520 KB |
Output is correct |
42 |
Correct |
136 ms |
17460 KB |
Output is correct |
43 |
Correct |
140 ms |
18684 KB |
Output is correct |
44 |
Correct |
122 ms |
18636 KB |
Output is correct |
45 |
Correct |
110 ms |
18692 KB |
Output is correct |
46 |
Correct |
120 ms |
18696 KB |
Output is correct |
47 |
Correct |
130 ms |
18704 KB |
Output is correct |
48 |
Correct |
140 ms |
18700 KB |
Output is correct |
49 |
Correct |
137 ms |
18696 KB |
Output is correct |
50 |
Correct |
117 ms |
18732 KB |
Output is correct |
51 |
Correct |
96 ms |
18688 KB |
Output is correct |
52 |
Correct |
103 ms |
18704 KB |
Output is correct |
53 |
Correct |
3 ms |
6484 KB |
Output is correct |
54 |
Incorrect |
165 ms |
18776 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |