#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
vector<vector<int>> w;
vector<ll> vals;
vector<int> r, p;
int find(int a) { return a == p[a] ? a : p[a] = find(p[a]); }
void link(int a, int b) {
a = find(a), b = find(b);
if (a == b) return;
if (r[a] < r[b]) swap(a, b);
if (r[a] == r[b]) ++r[a];
p[b] = a;
}
int main() {
int n, m; cin >> n >> m;
vector<int> arr(n); for (int i = 0; i < n; ++i) cin >> arr[i];
set<int> nums; for (int num : arr) nums.insert(num);
vector<int> copy(nums.begin(), nums.end());
vector<vector<pii>> edges(copy.size());
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b; --a, --b;
edges[lower_bound(copy.begin(), copy.end(), max(arr[a], arr[b])) - copy.begin()].push_back({a, b});
}
w.resize(n), vals.resize(n), r.resize(n), p.resize(n);
for (int i = 0; i < n; ++i) w[i].push_back(i), vals[i] = arr[i], p[i] = i;
for (int i = 0; i < copy.size(); ++i) {
for (pii edge : edges[i]) {
int a = edge.first, b = edge.second;
int pa = find(a), pb = find(b);
if (pa == pb) continue;
link(a, b);
int np = find(a);
if (vals[pa] < arr[b]) swap(w[np], w[pb]);
else if (vals[pb] < arr[a]) swap(w[np], w[pa]);
else {
if (w[pa].size() < w[pb].size()) swap(w[pa], w[pb]);
for (int v : w[pb]) w[pa].push_back(v);
swap(w[np], w[pa]);
}
vals[np] = vals[pa] + vals[pb];
}
}
vector<bool> ans(n);
for (int v : w[find(0)]) ans[v] = true;
for (int num : ans) cout << num;
cout << '\n';
return 0;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:33:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < copy.size(); ++i) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
528 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
608 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
332 ms |
36132 KB |
Output is correct |
4 |
Correct |
222 ms |
24252 KB |
Output is correct |
5 |
Correct |
328 ms |
36364 KB |
Output is correct |
6 |
Correct |
378 ms |
33448 KB |
Output is correct |
7 |
Correct |
350 ms |
37568 KB |
Output is correct |
8 |
Correct |
267 ms |
22780 KB |
Output is correct |
9 |
Correct |
306 ms |
33772 KB |
Output is correct |
10 |
Correct |
235 ms |
28356 KB |
Output is correct |
11 |
Correct |
208 ms |
19000 KB |
Output is correct |
12 |
Correct |
241 ms |
19120 KB |
Output is correct |
13 |
Correct |
240 ms |
25300 KB |
Output is correct |
14 |
Correct |
243 ms |
25024 KB |
Output is correct |
15 |
Correct |
341 ms |
38092 KB |
Output is correct |
16 |
Correct |
263 ms |
37588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
495 ms |
38552 KB |
Output is correct |
3 |
Correct |
445 ms |
35132 KB |
Output is correct |
4 |
Correct |
298 ms |
26112 KB |
Output is correct |
5 |
Correct |
253 ms |
26180 KB |
Output is correct |
6 |
Correct |
464 ms |
39252 KB |
Output is correct |
7 |
Correct |
353 ms |
38612 KB |
Output is correct |
8 |
Correct |
344 ms |
38584 KB |
Output is correct |
9 |
Correct |
264 ms |
38152 KB |
Output is correct |
10 |
Correct |
342 ms |
29436 KB |
Output is correct |
11 |
Correct |
243 ms |
23812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
278 ms |
19328 KB |
Output is correct |
3 |
Correct |
275 ms |
20256 KB |
Output is correct |
4 |
Correct |
312 ms |
21532 KB |
Output is correct |
5 |
Correct |
275 ms |
22764 KB |
Output is correct |
6 |
Correct |
288 ms |
20640 KB |
Output is correct |
7 |
Correct |
235 ms |
19840 KB |
Output is correct |
8 |
Correct |
201 ms |
19356 KB |
Output is correct |
9 |
Correct |
158 ms |
11448 KB |
Output is correct |
10 |
Correct |
216 ms |
23628 KB |
Output is correct |
11 |
Correct |
220 ms |
23120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
528 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
608 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
296 KB |
Output is correct |
16 |
Correct |
0 ms |
296 KB |
Output is correct |
17 |
Correct |
332 ms |
36132 KB |
Output is correct |
18 |
Correct |
222 ms |
24252 KB |
Output is correct |
19 |
Correct |
328 ms |
36364 KB |
Output is correct |
20 |
Correct |
378 ms |
33448 KB |
Output is correct |
21 |
Correct |
350 ms |
37568 KB |
Output is correct |
22 |
Correct |
267 ms |
22780 KB |
Output is correct |
23 |
Correct |
306 ms |
33772 KB |
Output is correct |
24 |
Correct |
235 ms |
28356 KB |
Output is correct |
25 |
Correct |
208 ms |
19000 KB |
Output is correct |
26 |
Correct |
241 ms |
19120 KB |
Output is correct |
27 |
Correct |
240 ms |
25300 KB |
Output is correct |
28 |
Correct |
243 ms |
25024 KB |
Output is correct |
29 |
Correct |
341 ms |
38092 KB |
Output is correct |
30 |
Correct |
263 ms |
37588 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
495 ms |
38552 KB |
Output is correct |
33 |
Correct |
445 ms |
35132 KB |
Output is correct |
34 |
Correct |
298 ms |
26112 KB |
Output is correct |
35 |
Correct |
253 ms |
26180 KB |
Output is correct |
36 |
Correct |
464 ms |
39252 KB |
Output is correct |
37 |
Correct |
353 ms |
38612 KB |
Output is correct |
38 |
Correct |
344 ms |
38584 KB |
Output is correct |
39 |
Correct |
264 ms |
38152 KB |
Output is correct |
40 |
Correct |
342 ms |
29436 KB |
Output is correct |
41 |
Correct |
243 ms |
23812 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
278 ms |
19328 KB |
Output is correct |
44 |
Correct |
275 ms |
20256 KB |
Output is correct |
45 |
Correct |
312 ms |
21532 KB |
Output is correct |
46 |
Correct |
275 ms |
22764 KB |
Output is correct |
47 |
Correct |
288 ms |
20640 KB |
Output is correct |
48 |
Correct |
235 ms |
19840 KB |
Output is correct |
49 |
Correct |
201 ms |
19356 KB |
Output is correct |
50 |
Correct |
158 ms |
11448 KB |
Output is correct |
51 |
Correct |
216 ms |
23628 KB |
Output is correct |
52 |
Correct |
220 ms |
23120 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
300 KB |
Output is correct |
56 |
Correct |
3 ms |
640 KB |
Output is correct |
57 |
Correct |
3 ms |
596 KB |
Output is correct |
58 |
Correct |
2 ms |
440 KB |
Output is correct |
59 |
Correct |
3 ms |
592 KB |
Output is correct |
60 |
Correct |
3 ms |
468 KB |
Output is correct |
61 |
Correct |
2 ms |
440 KB |
Output is correct |
62 |
Correct |
3 ms |
564 KB |
Output is correct |
63 |
Correct |
3 ms |
596 KB |
Output is correct |
64 |
Correct |
3 ms |
596 KB |
Output is correct |
65 |
Correct |
2 ms |
468 KB |
Output is correct |
66 |
Correct |
2 ms |
468 KB |
Output is correct |
67 |
Correct |
337 ms |
36788 KB |
Output is correct |
68 |
Correct |
223 ms |
25092 KB |
Output is correct |
69 |
Correct |
338 ms |
37228 KB |
Output is correct |
70 |
Correct |
329 ms |
34368 KB |
Output is correct |
71 |
Correct |
350 ms |
38440 KB |
Output is correct |
72 |
Correct |
280 ms |
23572 KB |
Output is correct |
73 |
Correct |
316 ms |
34696 KB |
Output is correct |
74 |
Correct |
237 ms |
29252 KB |
Output is correct |
75 |
Correct |
205 ms |
19884 KB |
Output is correct |
76 |
Correct |
212 ms |
20084 KB |
Output is correct |
77 |
Correct |
231 ms |
26372 KB |
Output is correct |
78 |
Correct |
233 ms |
25892 KB |
Output is correct |
79 |
Correct |
377 ms |
38664 KB |
Output is correct |
80 |
Correct |
264 ms |
38344 KB |
Output is correct |
81 |
Correct |
411 ms |
39088 KB |
Output is correct |
82 |
Correct |
375 ms |
35128 KB |
Output is correct |
83 |
Correct |
275 ms |
26144 KB |
Output is correct |
84 |
Correct |
218 ms |
26120 KB |
Output is correct |
85 |
Correct |
418 ms |
39264 KB |
Output is correct |
86 |
Correct |
323 ms |
38436 KB |
Output is correct |
87 |
Correct |
316 ms |
38420 KB |
Output is correct |
88 |
Correct |
259 ms |
29284 KB |
Output is correct |
89 |
Correct |
226 ms |
23632 KB |
Output is correct |
90 |
Correct |
248 ms |
19764 KB |
Output is correct |
91 |
Correct |
248 ms |
20112 KB |
Output is correct |
92 |
Correct |
253 ms |
21424 KB |
Output is correct |
93 |
Correct |
256 ms |
22688 KB |
Output is correct |
94 |
Correct |
257 ms |
20548 KB |
Output is correct |
95 |
Correct |
228 ms |
19768 KB |
Output is correct |
96 |
Correct |
184 ms |
19216 KB |
Output is correct |
97 |
Correct |
152 ms |
11376 KB |
Output is correct |
98 |
Correct |
220 ms |
23336 KB |
Output is correct |
99 |
Correct |
203 ms |
22892 KB |
Output is correct |
100 |
Correct |
109 ms |
4228 KB |
Output is correct |
101 |
Correct |
378 ms |
33400 KB |
Output is correct |
102 |
Correct |
223 ms |
16832 KB |
Output is correct |
103 |
Correct |
305 ms |
27356 KB |
Output is correct |
104 |
Correct |
406 ms |
35992 KB |
Output is correct |