#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
const int mxn = 2e5 + 100;
vector<ll> s(mxn), ldr(mxn), rnk(mxn), mx(mxn), p[mxn];
int Find(int x) {
if (ldr[x] == x) return x;
return ldr[x] = Find(ldr[x]);
}
void Union(int x, int y) {
x = Find(x), y = Find(y);
if (x == y) return;
if (rnk[x] < mx[y]) p[x].clear();
if (rnk[y] < mx[x]) p[y].clear();
if (p[x].size() < p[y].size()) swap(x, y);
for (auto el : p[y]) p[x].push_back(el);
ldr[y] = x;
rnk[x] += rnk[y];
mx[x] = max(mx[x], mx[y]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> s[i];
vector<pair<int, int>> edg;
for (int i = 0; i < m; i++) {
int f, t;
cin >> f >> t;
edg.push_back({f, t});
}
sort(all(edg), [&] (pair<int, int> a, pair<int, int> b) {
return max(s[a.first], s[a.second]) < max(s[b.first], s[b.second]);
});
for (int i = 1; i <= n; i++) {
ldr[i] = i;
rnk[i] = s[i];
p[i] = {i};
mx[i] = s[i];
}
for (auto x : edg) Union(x.first, x.second);
bitset<mxn> ans;
for (auto x : p[Find(1)]) ans[x] = 1;
for (int i = 1; i <= n; i++) cout << ans[i];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
11352 KB |
Output is correct |
2 |
Correct |
3 ms |
11456 KB |
Output is correct |
3 |
Correct |
4 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
11356 KB |
Output is correct |
5 |
Correct |
4 ms |
11612 KB |
Output is correct |
6 |
Correct |
3 ms |
11356 KB |
Output is correct |
7 |
Correct |
3 ms |
11356 KB |
Output is correct |
8 |
Correct |
3 ms |
11356 KB |
Output is correct |
9 |
Correct |
3 ms |
11356 KB |
Output is correct |
10 |
Correct |
4 ms |
11612 KB |
Output is correct |
11 |
Correct |
4 ms |
11612 KB |
Output is correct |
12 |
Correct |
4 ms |
11612 KB |
Output is correct |
13 |
Correct |
3 ms |
11612 KB |
Output is correct |
14 |
Correct |
4 ms |
11356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
3 ms |
11352 KB |
Output is correct |
3 |
Correct |
70 ms |
22596 KB |
Output is correct |
4 |
Correct |
76 ms |
34764 KB |
Output is correct |
5 |
Correct |
84 ms |
25548 KB |
Output is correct |
6 |
Correct |
80 ms |
26060 KB |
Output is correct |
7 |
Correct |
89 ms |
26056 KB |
Output is correct |
8 |
Correct |
85 ms |
30664 KB |
Output is correct |
9 |
Correct |
69 ms |
28876 KB |
Output is correct |
10 |
Correct |
49 ms |
19288 KB |
Output is correct |
11 |
Correct |
58 ms |
22216 KB |
Output is correct |
12 |
Correct |
75 ms |
24012 KB |
Output is correct |
13 |
Correct |
77 ms |
36296 KB |
Output is correct |
14 |
Correct |
78 ms |
34396 KB |
Output is correct |
15 |
Correct |
69 ms |
22220 KB |
Output is correct |
16 |
Correct |
48 ms |
22220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
11352 KB |
Output is correct |
2 |
Correct |
79 ms |
27592 KB |
Output is correct |
3 |
Correct |
82 ms |
27848 KB |
Output is correct |
4 |
Correct |
80 ms |
35892 KB |
Output is correct |
5 |
Correct |
73 ms |
36296 KB |
Output is correct |
6 |
Correct |
81 ms |
27448 KB |
Output is correct |
7 |
Correct |
63 ms |
22216 KB |
Output is correct |
8 |
Correct |
65 ms |
22216 KB |
Output is correct |
9 |
Correct |
46 ms |
22216 KB |
Output is correct |
10 |
Correct |
64 ms |
27684 KB |
Output is correct |
11 |
Correct |
71 ms |
29528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
11352 KB |
Output is correct |
2 |
Correct |
78 ms |
23088 KB |
Output is correct |
3 |
Correct |
83 ms |
28620 KB |
Output is correct |
4 |
Correct |
79 ms |
30664 KB |
Output is correct |
5 |
Correct |
77 ms |
33740 KB |
Output is correct |
6 |
Correct |
76 ms |
29968 KB |
Output is correct |
7 |
Correct |
60 ms |
26568 KB |
Output is correct |
8 |
Correct |
59 ms |
28508 KB |
Output is correct |
9 |
Correct |
44 ms |
20360 KB |
Output is correct |
10 |
Correct |
74 ms |
33632 KB |
Output is correct |
11 |
Correct |
72 ms |
32456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
11352 KB |
Output is correct |
2 |
Correct |
3 ms |
11456 KB |
Output is correct |
3 |
Correct |
4 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
11356 KB |
Output is correct |
5 |
Correct |
4 ms |
11612 KB |
Output is correct |
6 |
Correct |
3 ms |
11356 KB |
Output is correct |
7 |
Correct |
3 ms |
11356 KB |
Output is correct |
8 |
Correct |
3 ms |
11356 KB |
Output is correct |
9 |
Correct |
3 ms |
11356 KB |
Output is correct |
10 |
Correct |
4 ms |
11612 KB |
Output is correct |
11 |
Correct |
4 ms |
11612 KB |
Output is correct |
12 |
Correct |
4 ms |
11612 KB |
Output is correct |
13 |
Correct |
3 ms |
11612 KB |
Output is correct |
14 |
Correct |
4 ms |
11356 KB |
Output is correct |
15 |
Correct |
4 ms |
11352 KB |
Output is correct |
16 |
Correct |
3 ms |
11352 KB |
Output is correct |
17 |
Correct |
70 ms |
22596 KB |
Output is correct |
18 |
Correct |
76 ms |
34764 KB |
Output is correct |
19 |
Correct |
84 ms |
25548 KB |
Output is correct |
20 |
Correct |
80 ms |
26060 KB |
Output is correct |
21 |
Correct |
89 ms |
26056 KB |
Output is correct |
22 |
Correct |
85 ms |
30664 KB |
Output is correct |
23 |
Correct |
69 ms |
28876 KB |
Output is correct |
24 |
Correct |
49 ms |
19288 KB |
Output is correct |
25 |
Correct |
58 ms |
22216 KB |
Output is correct |
26 |
Correct |
75 ms |
24012 KB |
Output is correct |
27 |
Correct |
77 ms |
36296 KB |
Output is correct |
28 |
Correct |
78 ms |
34396 KB |
Output is correct |
29 |
Correct |
69 ms |
22220 KB |
Output is correct |
30 |
Correct |
48 ms |
22220 KB |
Output is correct |
31 |
Correct |
4 ms |
11352 KB |
Output is correct |
32 |
Correct |
79 ms |
27592 KB |
Output is correct |
33 |
Correct |
82 ms |
27848 KB |
Output is correct |
34 |
Correct |
80 ms |
35892 KB |
Output is correct |
35 |
Correct |
73 ms |
36296 KB |
Output is correct |
36 |
Correct |
81 ms |
27448 KB |
Output is correct |
37 |
Correct |
63 ms |
22216 KB |
Output is correct |
38 |
Correct |
65 ms |
22216 KB |
Output is correct |
39 |
Correct |
46 ms |
22216 KB |
Output is correct |
40 |
Correct |
64 ms |
27684 KB |
Output is correct |
41 |
Correct |
71 ms |
29528 KB |
Output is correct |
42 |
Correct |
3 ms |
11352 KB |
Output is correct |
43 |
Correct |
78 ms |
23088 KB |
Output is correct |
44 |
Correct |
83 ms |
28620 KB |
Output is correct |
45 |
Correct |
79 ms |
30664 KB |
Output is correct |
46 |
Correct |
77 ms |
33740 KB |
Output is correct |
47 |
Correct |
76 ms |
29968 KB |
Output is correct |
48 |
Correct |
60 ms |
26568 KB |
Output is correct |
49 |
Correct |
59 ms |
28508 KB |
Output is correct |
50 |
Correct |
44 ms |
20360 KB |
Output is correct |
51 |
Correct |
74 ms |
33632 KB |
Output is correct |
52 |
Correct |
72 ms |
32456 KB |
Output is correct |
53 |
Correct |
3 ms |
11356 KB |
Output is correct |
54 |
Correct |
3 ms |
11356 KB |
Output is correct |
55 |
Correct |
3 ms |
11356 KB |
Output is correct |
56 |
Correct |
4 ms |
11356 KB |
Output is correct |
57 |
Correct |
4 ms |
11608 KB |
Output is correct |
58 |
Correct |
3 ms |
11356 KB |
Output is correct |
59 |
Correct |
4 ms |
11356 KB |
Output is correct |
60 |
Correct |
4 ms |
11376 KB |
Output is correct |
61 |
Correct |
4 ms |
11356 KB |
Output is correct |
62 |
Correct |
3 ms |
11612 KB |
Output is correct |
63 |
Correct |
3 ms |
11472 KB |
Output is correct |
64 |
Correct |
4 ms |
11608 KB |
Output is correct |
65 |
Correct |
4 ms |
11608 KB |
Output is correct |
66 |
Correct |
3 ms |
11356 KB |
Output is correct |
67 |
Correct |
71 ms |
26896 KB |
Output is correct |
68 |
Correct |
81 ms |
37836 KB |
Output is correct |
69 |
Correct |
78 ms |
29644 KB |
Output is correct |
70 |
Correct |
80 ms |
30480 KB |
Output is correct |
71 |
Correct |
80 ms |
30448 KB |
Output is correct |
72 |
Correct |
84 ms |
35296 KB |
Output is correct |
73 |
Correct |
74 ms |
33224 KB |
Output is correct |
74 |
Correct |
57 ms |
22984 KB |
Output is correct |
75 |
Correct |
61 ms |
25544 KB |
Output is correct |
76 |
Correct |
70 ms |
26824 KB |
Output is correct |
77 |
Correct |
78 ms |
39068 KB |
Output is correct |
78 |
Correct |
83 ms |
37584 KB |
Output is correct |
79 |
Correct |
65 ms |
26568 KB |
Output is correct |
80 |
Correct |
50 ms |
25800 KB |
Output is correct |
81 |
Correct |
102 ms |
31840 KB |
Output is correct |
82 |
Correct |
86 ms |
32200 KB |
Output is correct |
83 |
Correct |
89 ms |
40396 KB |
Output is correct |
84 |
Correct |
77 ms |
39368 KB |
Output is correct |
85 |
Correct |
88 ms |
31908 KB |
Output is correct |
86 |
Correct |
65 ms |
26708 KB |
Output is correct |
87 |
Correct |
70 ms |
26824 KB |
Output is correct |
88 |
Correct |
72 ms |
31436 KB |
Output is correct |
89 |
Correct |
69 ms |
32460 KB |
Output is correct |
90 |
Correct |
82 ms |
27596 KB |
Output is correct |
91 |
Correct |
71 ms |
28544 KB |
Output is correct |
92 |
Correct |
74 ms |
30664 KB |
Output is correct |
93 |
Correct |
84 ms |
33724 KB |
Output is correct |
94 |
Correct |
76 ms |
29900 KB |
Output is correct |
95 |
Correct |
67 ms |
26568 KB |
Output is correct |
96 |
Correct |
56 ms |
28616 KB |
Output is correct |
97 |
Correct |
44 ms |
20276 KB |
Output is correct |
98 |
Correct |
72 ms |
33632 KB |
Output is correct |
99 |
Correct |
65 ms |
32428 KB |
Output is correct |
100 |
Correct |
34 ms |
15048 KB |
Output is correct |
101 |
Correct |
78 ms |
28872 KB |
Output is correct |
102 |
Correct |
58 ms |
26828 KB |
Output is correct |
103 |
Correct |
74 ms |
24524 KB |
Output is correct |
104 |
Correct |
81 ms |
26824 KB |
Output is correct |