//
// Created by 42kangaroo on 16/04/2023.
//
#include "bits/stdc++.h"
using namespace std;
#define int long long
using g_t = vector<vector<int>>;
int find(int a, vector<int>& p, vector<bool>& pos) {
if (a == p[a]) return a;
int par = find(p[a], p, pos);
if (!pos[p[a]]) pos[a] = false;
return p[a] = par;
}
void unite(int a, int b, vector<int>& p, vector<int>& s, vector<bool>& pos) {
a = find(a, p, pos);
b = find(b, p, pos);
if (a == b) return;
p[b] = a;
s[a] += s[b];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n>> m;
vector<int> s(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
g_t gr(n);
for (int i = 0; i < m; ++i) {
int a, b;
cin>> a >> b;
--a;--b;
gr[a].push_back(b);
gr[b].push_back(a);
}
vector<int> ns = s;
vector<int> o(n);
std::iota(o.begin(), o.end(),0);
std::sort(o.begin(), o.end(),[&](int l, int r){return s[l] < s[r];});
vector<int> p(n);
std::iota(p.begin(), p.end(),0);
vector<bool> pos(n, true);
for (int i = 0; i < n; ++i) {
for (auto e: gr[o[i]]) {
if (s[e] > s[o[i]]) continue;
if (ns[find(e, p, pos)] < s[o[i]]) pos[find(e, p, pos)] = false;
unite(o[i], e, p, ns, pos);
}
}
for (int i = 0; i < n; ++i) {
find(i, p, pos);
cout << pos[i];
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
147 ms |
23124 KB |
Output is correct |
4 |
Correct |
151 ms |
21804 KB |
Output is correct |
5 |
Correct |
147 ms |
22408 KB |
Output is correct |
6 |
Correct |
162 ms |
23060 KB |
Output is correct |
7 |
Correct |
152 ms |
23112 KB |
Output is correct |
8 |
Correct |
176 ms |
23192 KB |
Output is correct |
9 |
Correct |
168 ms |
24396 KB |
Output is correct |
10 |
Correct |
118 ms |
22780 KB |
Output is correct |
11 |
Correct |
133 ms |
27708 KB |
Output is correct |
12 |
Correct |
180 ms |
21740 KB |
Output is correct |
13 |
Correct |
166 ms |
20600 KB |
Output is correct |
14 |
Correct |
136 ms |
20748 KB |
Output is correct |
15 |
Correct |
139 ms |
22148 KB |
Output is correct |
16 |
Correct |
110 ms |
21324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
187 ms |
22076 KB |
Output is correct |
3 |
Correct |
204 ms |
22224 KB |
Output is correct |
4 |
Correct |
135 ms |
22192 KB |
Output is correct |
5 |
Correct |
131 ms |
20604 KB |
Output is correct |
6 |
Correct |
193 ms |
22260 KB |
Output is correct |
7 |
Correct |
171 ms |
22108 KB |
Output is correct |
8 |
Correct |
181 ms |
22296 KB |
Output is correct |
9 |
Correct |
85 ms |
21292 KB |
Output is correct |
10 |
Correct |
144 ms |
21496 KB |
Output is correct |
11 |
Correct |
155 ms |
20732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
220 ms |
23116 KB |
Output is correct |
3 |
Correct |
192 ms |
23024 KB |
Output is correct |
4 |
Correct |
178 ms |
23244 KB |
Output is correct |
5 |
Correct |
188 ms |
23148 KB |
Output is correct |
6 |
Correct |
221 ms |
22284 KB |
Output is correct |
7 |
Correct |
137 ms |
30300 KB |
Output is correct |
8 |
Correct |
106 ms |
22612 KB |
Output is correct |
9 |
Correct |
135 ms |
14304 KB |
Output is correct |
10 |
Correct |
170 ms |
21660 KB |
Output is correct |
11 |
Correct |
161 ms |
20692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
147 ms |
23124 KB |
Output is correct |
18 |
Correct |
151 ms |
21804 KB |
Output is correct |
19 |
Correct |
147 ms |
22408 KB |
Output is correct |
20 |
Correct |
162 ms |
23060 KB |
Output is correct |
21 |
Correct |
152 ms |
23112 KB |
Output is correct |
22 |
Correct |
176 ms |
23192 KB |
Output is correct |
23 |
Correct |
168 ms |
24396 KB |
Output is correct |
24 |
Correct |
118 ms |
22780 KB |
Output is correct |
25 |
Correct |
133 ms |
27708 KB |
Output is correct |
26 |
Correct |
180 ms |
21740 KB |
Output is correct |
27 |
Correct |
166 ms |
20600 KB |
Output is correct |
28 |
Correct |
136 ms |
20748 KB |
Output is correct |
29 |
Correct |
139 ms |
22148 KB |
Output is correct |
30 |
Correct |
110 ms |
21324 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
187 ms |
22076 KB |
Output is correct |
33 |
Correct |
204 ms |
22224 KB |
Output is correct |
34 |
Correct |
135 ms |
22192 KB |
Output is correct |
35 |
Correct |
131 ms |
20604 KB |
Output is correct |
36 |
Correct |
193 ms |
22260 KB |
Output is correct |
37 |
Correct |
171 ms |
22108 KB |
Output is correct |
38 |
Correct |
181 ms |
22296 KB |
Output is correct |
39 |
Correct |
85 ms |
21292 KB |
Output is correct |
40 |
Correct |
144 ms |
21496 KB |
Output is correct |
41 |
Correct |
155 ms |
20732 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
220 ms |
23116 KB |
Output is correct |
44 |
Correct |
192 ms |
23024 KB |
Output is correct |
45 |
Correct |
178 ms |
23244 KB |
Output is correct |
46 |
Correct |
188 ms |
23148 KB |
Output is correct |
47 |
Correct |
221 ms |
22284 KB |
Output is correct |
48 |
Correct |
137 ms |
30300 KB |
Output is correct |
49 |
Correct |
106 ms |
22612 KB |
Output is correct |
50 |
Correct |
135 ms |
14304 KB |
Output is correct |
51 |
Correct |
170 ms |
21660 KB |
Output is correct |
52 |
Correct |
161 ms |
20692 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
316 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
468 KB |
Output is correct |
57 |
Correct |
2 ms |
476 KB |
Output is correct |
58 |
Correct |
2 ms |
468 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
456 KB |
Output is correct |
62 |
Correct |
2 ms |
460 KB |
Output is correct |
63 |
Correct |
2 ms |
504 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
2 ms |
468 KB |
Output is correct |
66 |
Correct |
3 ms |
468 KB |
Output is correct |
67 |
Correct |
185 ms |
23112 KB |
Output is correct |
68 |
Correct |
132 ms |
21864 KB |
Output is correct |
69 |
Correct |
147 ms |
22360 KB |
Output is correct |
70 |
Correct |
188 ms |
23112 KB |
Output is correct |
71 |
Correct |
161 ms |
23124 KB |
Output is correct |
72 |
Correct |
177 ms |
23124 KB |
Output is correct |
73 |
Correct |
152 ms |
24372 KB |
Output is correct |
74 |
Correct |
129 ms |
22884 KB |
Output is correct |
75 |
Correct |
115 ms |
27664 KB |
Output is correct |
76 |
Correct |
154 ms |
21772 KB |
Output is correct |
77 |
Correct |
157 ms |
20656 KB |
Output is correct |
78 |
Correct |
134 ms |
20808 KB |
Output is correct |
79 |
Correct |
130 ms |
22100 KB |
Output is correct |
80 |
Correct |
83 ms |
21312 KB |
Output is correct |
81 |
Correct |
180 ms |
22060 KB |
Output is correct |
82 |
Correct |
171 ms |
22220 KB |
Output is correct |
83 |
Correct |
135 ms |
22208 KB |
Output is correct |
84 |
Correct |
137 ms |
20604 KB |
Output is correct |
85 |
Correct |
200 ms |
22136 KB |
Output is correct |
86 |
Correct |
160 ms |
22164 KB |
Output is correct |
87 |
Correct |
157 ms |
22240 KB |
Output is correct |
88 |
Correct |
148 ms |
21576 KB |
Output is correct |
89 |
Correct |
145 ms |
20624 KB |
Output is correct |
90 |
Correct |
182 ms |
23056 KB |
Output is correct |
91 |
Correct |
192 ms |
22992 KB |
Output is correct |
92 |
Correct |
197 ms |
23240 KB |
Output is correct |
93 |
Correct |
182 ms |
23128 KB |
Output is correct |
94 |
Correct |
198 ms |
22284 KB |
Output is correct |
95 |
Correct |
132 ms |
30300 KB |
Output is correct |
96 |
Correct |
93 ms |
22608 KB |
Output is correct |
97 |
Correct |
103 ms |
14304 KB |
Output is correct |
98 |
Correct |
185 ms |
21644 KB |
Output is correct |
99 |
Correct |
151 ms |
20612 KB |
Output is correct |
100 |
Correct |
44 ms |
6816 KB |
Output is correct |
101 |
Correct |
189 ms |
23164 KB |
Output is correct |
102 |
Correct |
173 ms |
19960 KB |
Output is correct |
103 |
Correct |
222 ms |
20704 KB |
Output is correct |
104 |
Correct |
196 ms |
22836 KB |
Output is correct |