#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 400400;
int dsu[N], sz[N];
int s[N];
vector<int> ch[N];
ll sum[N];
int node[N];
int w;
bool bad[N];
int ans[N];
void init(int n) {
for (int i = 1; i <= n; ++i) {
dsu[i] = i;
sz[i] = 1;
sum[i] = s[i];
node[i] = i;
}
}
int fs(int i) {
if (dsu[i] == i) return i;
return dsu[i] = fs(dsu[i]);
}
void us(int a, int b) {
int sa = s[a];
int sb = s[b];
a = fs(a);
b = fs(b);
if (a != b) {
if (sum[a] < sb) bad[node[a]] = 1;
if (sum[b] < sa) bad[node[b]] = 1;
if (sz[a] < sz[b]) swap(a, b);
dsu[b] = a;
sz[a] += sz[b];
sum[a] += sum[b];
ch[w].push_back(node[a]);
ch[w].push_back(node[b]);
node[a] = w++;
}
}
bool cmp(pii a, pii b) {
return make_pair(s[a.first], s[a.second]) < make_pair(s[b.first], s[b.second]);
}
void dfs(int u, int p, int c) {
c += bad[u];
if (ch[u].empty()) ans[u] = c == 0;
for (int v : ch[u]) {
dfs(v, u, c);
}
}
void solve() {
int n, m;
cin >> n >> m;
w = n+1;
for (int i = 1; i <= n; ++i) cin >> s[i];
vector<pii> e(m);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
if (s[u] < s[v]) swap(u, v);
e[i] = {u, v};
}
sort(e.begin(), e.end(), cmp);
init(n);
for (pii p : e) us(p.first, p.second);
dfs(w-1, -1, 0);
for (int i = 1; i <= n; ++i) cout << ans[i];
cout << '\n';
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18780 KB |
Output is correct |
2 |
Correct |
3 ms |
18780 KB |
Output is correct |
3 |
Correct |
3 ms |
18780 KB |
Output is correct |
4 |
Correct |
5 ms |
18780 KB |
Output is correct |
5 |
Correct |
4 ms |
18780 KB |
Output is correct |
6 |
Correct |
3 ms |
18780 KB |
Output is correct |
7 |
Correct |
4 ms |
18780 KB |
Output is correct |
8 |
Correct |
4 ms |
18780 KB |
Output is correct |
9 |
Correct |
4 ms |
19036 KB |
Output is correct |
10 |
Correct |
4 ms |
18940 KB |
Output is correct |
11 |
Correct |
5 ms |
18780 KB |
Output is correct |
12 |
Correct |
4 ms |
18776 KB |
Output is correct |
13 |
Correct |
4 ms |
18780 KB |
Output is correct |
14 |
Correct |
4 ms |
18780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18780 KB |
Output is correct |
2 |
Correct |
3 ms |
18780 KB |
Output is correct |
3 |
Correct |
95 ms |
31576 KB |
Output is correct |
4 |
Correct |
88 ms |
29008 KB |
Output is correct |
5 |
Correct |
107 ms |
28852 KB |
Output is correct |
6 |
Correct |
113 ms |
29016 KB |
Output is correct |
7 |
Correct |
112 ms |
28964 KB |
Output is correct |
8 |
Correct |
115 ms |
29444 KB |
Output is correct |
9 |
Correct |
90 ms |
29012 KB |
Output is correct |
10 |
Correct |
84 ms |
33620 KB |
Output is correct |
11 |
Correct |
76 ms |
33500 KB |
Output is correct |
12 |
Correct |
91 ms |
29096 KB |
Output is correct |
13 |
Correct |
82 ms |
29008 KB |
Output is correct |
14 |
Correct |
82 ms |
28948 KB |
Output is correct |
15 |
Correct |
91 ms |
33552 KB |
Output is correct |
16 |
Correct |
70 ms |
33532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18780 KB |
Output is correct |
2 |
Correct |
114 ms |
28904 KB |
Output is correct |
3 |
Correct |
109 ms |
33520 KB |
Output is correct |
4 |
Correct |
95 ms |
33652 KB |
Output is correct |
5 |
Correct |
83 ms |
32084 KB |
Output is correct |
6 |
Correct |
107 ms |
33404 KB |
Output is correct |
7 |
Correct |
92 ms |
38136 KB |
Output is correct |
8 |
Correct |
92 ms |
38104 KB |
Output is correct |
9 |
Correct |
71 ms |
37200 KB |
Output is correct |
10 |
Correct |
90 ms |
36228 KB |
Output is correct |
11 |
Correct |
89 ms |
32000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18776 KB |
Output is correct |
2 |
Correct |
110 ms |
29440 KB |
Output is correct |
3 |
Correct |
110 ms |
33620 KB |
Output is correct |
4 |
Correct |
127 ms |
33620 KB |
Output is correct |
5 |
Correct |
99 ms |
33624 KB |
Output is correct |
6 |
Correct |
95 ms |
33636 KB |
Output is correct |
7 |
Correct |
81 ms |
37968 KB |
Output is correct |
8 |
Correct |
74 ms |
34532 KB |
Output is correct |
9 |
Correct |
69 ms |
28520 KB |
Output is correct |
10 |
Correct |
92 ms |
32084 KB |
Output is correct |
11 |
Correct |
92 ms |
32084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18780 KB |
Output is correct |
2 |
Correct |
3 ms |
18780 KB |
Output is correct |
3 |
Correct |
3 ms |
18780 KB |
Output is correct |
4 |
Correct |
5 ms |
18780 KB |
Output is correct |
5 |
Correct |
4 ms |
18780 KB |
Output is correct |
6 |
Correct |
3 ms |
18780 KB |
Output is correct |
7 |
Correct |
4 ms |
18780 KB |
Output is correct |
8 |
Correct |
4 ms |
18780 KB |
Output is correct |
9 |
Correct |
4 ms |
19036 KB |
Output is correct |
10 |
Correct |
4 ms |
18940 KB |
Output is correct |
11 |
Correct |
5 ms |
18780 KB |
Output is correct |
12 |
Correct |
4 ms |
18776 KB |
Output is correct |
13 |
Correct |
4 ms |
18780 KB |
Output is correct |
14 |
Correct |
4 ms |
18780 KB |
Output is correct |
15 |
Correct |
4 ms |
18780 KB |
Output is correct |
16 |
Correct |
3 ms |
18780 KB |
Output is correct |
17 |
Correct |
95 ms |
31576 KB |
Output is correct |
18 |
Correct |
88 ms |
29008 KB |
Output is correct |
19 |
Correct |
107 ms |
28852 KB |
Output is correct |
20 |
Correct |
113 ms |
29016 KB |
Output is correct |
21 |
Correct |
112 ms |
28964 KB |
Output is correct |
22 |
Correct |
115 ms |
29444 KB |
Output is correct |
23 |
Correct |
90 ms |
29012 KB |
Output is correct |
24 |
Correct |
84 ms |
33620 KB |
Output is correct |
25 |
Correct |
76 ms |
33500 KB |
Output is correct |
26 |
Correct |
91 ms |
29096 KB |
Output is correct |
27 |
Correct |
82 ms |
29008 KB |
Output is correct |
28 |
Correct |
82 ms |
28948 KB |
Output is correct |
29 |
Correct |
91 ms |
33552 KB |
Output is correct |
30 |
Correct |
70 ms |
33532 KB |
Output is correct |
31 |
Correct |
3 ms |
18780 KB |
Output is correct |
32 |
Correct |
114 ms |
28904 KB |
Output is correct |
33 |
Correct |
109 ms |
33520 KB |
Output is correct |
34 |
Correct |
95 ms |
33652 KB |
Output is correct |
35 |
Correct |
83 ms |
32084 KB |
Output is correct |
36 |
Correct |
107 ms |
33404 KB |
Output is correct |
37 |
Correct |
92 ms |
38136 KB |
Output is correct |
38 |
Correct |
92 ms |
38104 KB |
Output is correct |
39 |
Correct |
71 ms |
37200 KB |
Output is correct |
40 |
Correct |
90 ms |
36228 KB |
Output is correct |
41 |
Correct |
89 ms |
32000 KB |
Output is correct |
42 |
Correct |
3 ms |
18776 KB |
Output is correct |
43 |
Correct |
110 ms |
29440 KB |
Output is correct |
44 |
Correct |
110 ms |
33620 KB |
Output is correct |
45 |
Correct |
127 ms |
33620 KB |
Output is correct |
46 |
Correct |
99 ms |
33624 KB |
Output is correct |
47 |
Correct |
95 ms |
33636 KB |
Output is correct |
48 |
Correct |
81 ms |
37968 KB |
Output is correct |
49 |
Correct |
74 ms |
34532 KB |
Output is correct |
50 |
Correct |
69 ms |
28520 KB |
Output is correct |
51 |
Correct |
92 ms |
32084 KB |
Output is correct |
52 |
Correct |
92 ms |
32084 KB |
Output is correct |
53 |
Correct |
3 ms |
18780 KB |
Output is correct |
54 |
Correct |
4 ms |
18776 KB |
Output is correct |
55 |
Correct |
3 ms |
18780 KB |
Output is correct |
56 |
Correct |
4 ms |
19036 KB |
Output is correct |
57 |
Correct |
4 ms |
19036 KB |
Output is correct |
58 |
Correct |
4 ms |
18964 KB |
Output is correct |
59 |
Correct |
5 ms |
19232 KB |
Output is correct |
60 |
Correct |
4 ms |
18776 KB |
Output is correct |
61 |
Correct |
4 ms |
19036 KB |
Output is correct |
62 |
Correct |
4 ms |
19036 KB |
Output is correct |
63 |
Correct |
4 ms |
18932 KB |
Output is correct |
64 |
Correct |
4 ms |
19036 KB |
Output is correct |
65 |
Correct |
4 ms |
19036 KB |
Output is correct |
66 |
Correct |
4 ms |
18948 KB |
Output is correct |
67 |
Correct |
95 ms |
35940 KB |
Output is correct |
68 |
Correct |
84 ms |
32376 KB |
Output is correct |
69 |
Correct |
108 ms |
33108 KB |
Output is correct |
70 |
Correct |
113 ms |
33364 KB |
Output is correct |
71 |
Correct |
115 ms |
33404 KB |
Output is correct |
72 |
Correct |
114 ms |
33412 KB |
Output is correct |
73 |
Correct |
91 ms |
33360 KB |
Output is correct |
74 |
Correct |
86 ms |
37140 KB |
Output is correct |
75 |
Correct |
78 ms |
36944 KB |
Output is correct |
76 |
Correct |
108 ms |
32540 KB |
Output is correct |
77 |
Correct |
82 ms |
32084 KB |
Output is correct |
78 |
Correct |
83 ms |
32128 KB |
Output is correct |
79 |
Correct |
93 ms |
38052 KB |
Output is correct |
80 |
Correct |
72 ms |
37200 KB |
Output is correct |
81 |
Correct |
111 ms |
33364 KB |
Output is correct |
82 |
Correct |
108 ms |
33428 KB |
Output is correct |
83 |
Correct |
92 ms |
33740 KB |
Output is correct |
84 |
Correct |
82 ms |
31852 KB |
Output is correct |
85 |
Correct |
110 ms |
33868 KB |
Output is correct |
86 |
Correct |
109 ms |
37968 KB |
Output is correct |
87 |
Correct |
93 ms |
37968 KB |
Output is correct |
88 |
Correct |
89 ms |
36176 KB |
Output is correct |
89 |
Correct |
90 ms |
32084 KB |
Output is correct |
90 |
Correct |
108 ms |
33872 KB |
Output is correct |
91 |
Correct |
110 ms |
33392 KB |
Output is correct |
92 |
Correct |
111 ms |
33544 KB |
Output is correct |
93 |
Correct |
100 ms |
33620 KB |
Output is correct |
94 |
Correct |
96 ms |
33616 KB |
Output is correct |
95 |
Correct |
82 ms |
37972 KB |
Output is correct |
96 |
Correct |
77 ms |
34700 KB |
Output is correct |
97 |
Correct |
62 ms |
28500 KB |
Output is correct |
98 |
Correct |
92 ms |
32116 KB |
Output is correct |
99 |
Correct |
90 ms |
32084 KB |
Output is correct |
100 |
Correct |
52 ms |
22380 KB |
Output is correct |
101 |
Correct |
118 ms |
33616 KB |
Output is correct |
102 |
Correct |
83 ms |
32400 KB |
Output is correct |
103 |
Correct |
105 ms |
33620 KB |
Output is correct |
104 |
Correct |
113 ms |
33992 KB |
Output is correct |