#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int N, M, s[200005], e[200005];
vector<int> g[200005], h[200005];
int find(int u) {
return e[u] < 0 ? u : e[u] = find(e[u]);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> N >> M;
array<int, 2> byS[N];
for(int i = 0; i < N; ++i) {
cin >> s[i];
e[i] = -1;
h[i] = {i};
byS[i] = {s[i], i};
}
for(int i = 0; i < M; ++i) {
int u, v; cin >> u >> v;
--u, --v;
if(make_pair(s[u], u) < make_pair(s[v], v)) swap(u, v);
g[u].push_back(v);
}
sort(byS, byS + N);
for(auto [piss, r] : byS) {
int u = find(r);
for(int &v : g[r]) {
v = find(v);
if(s[v] < s[u]) h[v].clear();
if(size(h[v]) > size(h[u])) h[u].swap(h[v]);
}
for(int &v : g[r]) if((v = find(v)) != u) {
for(int y : h[v]) h[u].push_back(y);
s[u] += s[v];
e[v] = u;
}
}
for(int u : h[find(0)]) s[u] = -1;
for(int i = 0; i < N; ++i) cout << (s[i] < 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
3 ms |
12892 KB |
Output is correct |
8 |
Correct |
3 ms |
12892 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
13148 KB |
Output is correct |
11 |
Correct |
3 ms |
12888 KB |
Output is correct |
12 |
Correct |
3 ms |
12980 KB |
Output is correct |
13 |
Correct |
7 ms |
13144 KB |
Output is correct |
14 |
Correct |
3 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
3 ms |
12908 KB |
Output is correct |
3 |
Correct |
119 ms |
29196 KB |
Output is correct |
4 |
Correct |
93 ms |
31848 KB |
Output is correct |
5 |
Correct |
94 ms |
31424 KB |
Output is correct |
6 |
Correct |
101 ms |
32196 KB |
Output is correct |
7 |
Correct |
101 ms |
32200 KB |
Output is correct |
8 |
Correct |
107 ms |
30684 KB |
Output is correct |
9 |
Correct |
96 ms |
33752 KB |
Output is correct |
10 |
Correct |
61 ms |
24712 KB |
Output is correct |
11 |
Correct |
108 ms |
30768 KB |
Output is correct |
12 |
Correct |
119 ms |
30412 KB |
Output is correct |
13 |
Correct |
85 ms |
33640 KB |
Output is correct |
14 |
Correct |
94 ms |
33388 KB |
Output is correct |
15 |
Correct |
96 ms |
30772 KB |
Output is correct |
16 |
Correct |
66 ms |
30404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
136 ms |
33652 KB |
Output is correct |
3 |
Correct |
145 ms |
33928 KB |
Output is correct |
4 |
Correct |
156 ms |
33464 KB |
Output is correct |
5 |
Correct |
84 ms |
32872 KB |
Output is correct |
6 |
Correct |
155 ms |
33728 KB |
Output is correct |
7 |
Correct |
118 ms |
30796 KB |
Output is correct |
8 |
Correct |
115 ms |
30732 KB |
Output is correct |
9 |
Correct |
67 ms |
30404 KB |
Output is correct |
10 |
Correct |
99 ms |
28140 KB |
Output is correct |
11 |
Correct |
119 ms |
29828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
141 ms |
29628 KB |
Output is correct |
3 |
Correct |
170 ms |
30284 KB |
Output is correct |
4 |
Correct |
157 ms |
32452 KB |
Output is correct |
5 |
Correct |
148 ms |
34228 KB |
Output is correct |
6 |
Correct |
109 ms |
30660 KB |
Output is correct |
7 |
Correct |
83 ms |
28488 KB |
Output is correct |
8 |
Correct |
74 ms |
32328 KB |
Output is correct |
9 |
Correct |
86 ms |
22472 KB |
Output is correct |
10 |
Correct |
109 ms |
35648 KB |
Output is correct |
11 |
Correct |
116 ms |
29636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
3 ms |
12892 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
4 ms |
12892 KB |
Output is correct |
5 |
Correct |
4 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12892 KB |
Output is correct |
7 |
Correct |
3 ms |
12892 KB |
Output is correct |
8 |
Correct |
3 ms |
12892 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
13148 KB |
Output is correct |
11 |
Correct |
3 ms |
12888 KB |
Output is correct |
12 |
Correct |
3 ms |
12980 KB |
Output is correct |
13 |
Correct |
7 ms |
13144 KB |
Output is correct |
14 |
Correct |
3 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
3 ms |
12908 KB |
Output is correct |
17 |
Correct |
119 ms |
29196 KB |
Output is correct |
18 |
Correct |
93 ms |
31848 KB |
Output is correct |
19 |
Correct |
94 ms |
31424 KB |
Output is correct |
20 |
Correct |
101 ms |
32196 KB |
Output is correct |
21 |
Correct |
101 ms |
32200 KB |
Output is correct |
22 |
Correct |
107 ms |
30684 KB |
Output is correct |
23 |
Correct |
96 ms |
33752 KB |
Output is correct |
24 |
Correct |
61 ms |
24712 KB |
Output is correct |
25 |
Correct |
108 ms |
30768 KB |
Output is correct |
26 |
Correct |
119 ms |
30412 KB |
Output is correct |
27 |
Correct |
85 ms |
33640 KB |
Output is correct |
28 |
Correct |
94 ms |
33388 KB |
Output is correct |
29 |
Correct |
96 ms |
30772 KB |
Output is correct |
30 |
Correct |
66 ms |
30404 KB |
Output is correct |
31 |
Correct |
2 ms |
12892 KB |
Output is correct |
32 |
Correct |
136 ms |
33652 KB |
Output is correct |
33 |
Correct |
145 ms |
33928 KB |
Output is correct |
34 |
Correct |
156 ms |
33464 KB |
Output is correct |
35 |
Correct |
84 ms |
32872 KB |
Output is correct |
36 |
Correct |
155 ms |
33728 KB |
Output is correct |
37 |
Correct |
118 ms |
30796 KB |
Output is correct |
38 |
Correct |
115 ms |
30732 KB |
Output is correct |
39 |
Correct |
67 ms |
30404 KB |
Output is correct |
40 |
Correct |
99 ms |
28140 KB |
Output is correct |
41 |
Correct |
119 ms |
29828 KB |
Output is correct |
42 |
Correct |
2 ms |
12892 KB |
Output is correct |
43 |
Correct |
141 ms |
29628 KB |
Output is correct |
44 |
Correct |
170 ms |
30284 KB |
Output is correct |
45 |
Correct |
157 ms |
32452 KB |
Output is correct |
46 |
Correct |
148 ms |
34228 KB |
Output is correct |
47 |
Correct |
109 ms |
30660 KB |
Output is correct |
48 |
Correct |
83 ms |
28488 KB |
Output is correct |
49 |
Correct |
74 ms |
32328 KB |
Output is correct |
50 |
Correct |
86 ms |
22472 KB |
Output is correct |
51 |
Correct |
109 ms |
35648 KB |
Output is correct |
52 |
Correct |
116 ms |
29636 KB |
Output is correct |
53 |
Correct |
3 ms |
12888 KB |
Output is correct |
54 |
Correct |
3 ms |
12888 KB |
Output is correct |
55 |
Correct |
3 ms |
12948 KB |
Output is correct |
56 |
Correct |
3 ms |
12892 KB |
Output is correct |
57 |
Correct |
3 ms |
12888 KB |
Output is correct |
58 |
Correct |
4 ms |
12892 KB |
Output is correct |
59 |
Correct |
3 ms |
12892 KB |
Output is correct |
60 |
Correct |
3 ms |
12892 KB |
Output is correct |
61 |
Correct |
3 ms |
12892 KB |
Output is correct |
62 |
Correct |
4 ms |
13084 KB |
Output is correct |
63 |
Correct |
3 ms |
12888 KB |
Output is correct |
64 |
Correct |
3 ms |
12892 KB |
Output is correct |
65 |
Correct |
3 ms |
13148 KB |
Output is correct |
66 |
Correct |
4 ms |
12892 KB |
Output is correct |
67 |
Correct |
89 ms |
29192 KB |
Output is correct |
68 |
Correct |
98 ms |
31916 KB |
Output is correct |
69 |
Correct |
98 ms |
31492 KB |
Output is correct |
70 |
Correct |
100 ms |
32288 KB |
Output is correct |
71 |
Correct |
104 ms |
32456 KB |
Output is correct |
72 |
Correct |
124 ms |
30664 KB |
Output is correct |
73 |
Correct |
91 ms |
33736 KB |
Output is correct |
74 |
Correct |
61 ms |
24516 KB |
Output is correct |
75 |
Correct |
111 ms |
30668 KB |
Output is correct |
76 |
Correct |
146 ms |
30448 KB |
Output is correct |
77 |
Correct |
82 ms |
33468 KB |
Output is correct |
78 |
Correct |
92 ms |
33472 KB |
Output is correct |
79 |
Correct |
86 ms |
30788 KB |
Output is correct |
80 |
Correct |
67 ms |
30400 KB |
Output is correct |
81 |
Correct |
128 ms |
33720 KB |
Output is correct |
82 |
Correct |
131 ms |
33860 KB |
Output is correct |
83 |
Correct |
128 ms |
33504 KB |
Output is correct |
84 |
Correct |
88 ms |
32816 KB |
Output is correct |
85 |
Correct |
132 ms |
33732 KB |
Output is correct |
86 |
Correct |
127 ms |
30732 KB |
Output is correct |
87 |
Correct |
107 ms |
30664 KB |
Output is correct |
88 |
Correct |
93 ms |
28008 KB |
Output is correct |
89 |
Correct |
139 ms |
29812 KB |
Output is correct |
90 |
Correct |
142 ms |
29604 KB |
Output is correct |
91 |
Correct |
135 ms |
30284 KB |
Output is correct |
92 |
Correct |
139 ms |
32448 KB |
Output is correct |
93 |
Correct |
141 ms |
34124 KB |
Output is correct |
94 |
Correct |
126 ms |
30656 KB |
Output is correct |
95 |
Correct |
90 ms |
28696 KB |
Output is correct |
96 |
Correct |
71 ms |
32452 KB |
Output is correct |
97 |
Correct |
81 ms |
22476 KB |
Output is correct |
98 |
Correct |
118 ms |
35604 KB |
Output is correct |
99 |
Correct |
114 ms |
29712 KB |
Output is correct |
100 |
Correct |
31 ms |
15964 KB |
Output is correct |
101 |
Correct |
147 ms |
30768 KB |
Output is correct |
102 |
Correct |
121 ms |
27244 KB |
Output is correct |
103 |
Correct |
122 ms |
26316 KB |
Output is correct |
104 |
Correct |
168 ms |
28852 KB |
Output is correct |