#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int a[N];
int p[N];
bool s[N];
bool ans[N];
long long sum[N];
vector<int> g[N];
vector<int> sons[N];
int get (int v) {
if (p[v] < 0) return v;
return p[v] = get(p[v]);
}
void Dfs (int v) {
ans[v] = true;
for (int u : sons[v]) {
Dfs(u);
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
p[i] = -1;
sum[i] = a[i];
}
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int u, int v) {
return a[u] < a[v];
});
for (int i = 0; i < n; ++i) {
int v = ord[i];
s[v] = true;
for (int u : g[v]) {
u = get(u);
if (!s[u] || u == v) {
continue;
}
if (sum[u] >= a[v]) {
sons[v].push_back(u);
}
sum[v] += sum[u];
p[u] = v;
}
}
Dfs(ord.back());
for (int i = 1; i <= n; ++i) {
cout << ans[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9812 KB |
Output is correct |
4 |
Correct |
7 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9868 KB |
Output is correct |
6 |
Correct |
6 ms |
9860 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9772 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
7 ms |
9860 KB |
Output is correct |
11 |
Correct |
7 ms |
9816 KB |
Output is correct |
12 |
Correct |
7 ms |
9784 KB |
Output is correct |
13 |
Correct |
6 ms |
9864 KB |
Output is correct |
14 |
Correct |
6 ms |
9864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
149 ms |
25428 KB |
Output is correct |
4 |
Correct |
146 ms |
28916 KB |
Output is correct |
5 |
Correct |
186 ms |
26956 KB |
Output is correct |
6 |
Correct |
154 ms |
27464 KB |
Output is correct |
7 |
Correct |
152 ms |
27568 KB |
Output is correct |
8 |
Correct |
166 ms |
29264 KB |
Output is correct |
9 |
Correct |
143 ms |
26044 KB |
Output is correct |
10 |
Correct |
104 ms |
24548 KB |
Output is correct |
11 |
Correct |
107 ms |
25828 KB |
Output is correct |
12 |
Correct |
152 ms |
27044 KB |
Output is correct |
13 |
Correct |
138 ms |
29028 KB |
Output is correct |
14 |
Correct |
142 ms |
29108 KB |
Output is correct |
15 |
Correct |
138 ms |
34564 KB |
Output is correct |
16 |
Correct |
95 ms |
33716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
171 ms |
22740 KB |
Output is correct |
3 |
Correct |
202 ms |
27300 KB |
Output is correct |
4 |
Correct |
150 ms |
30700 KB |
Output is correct |
5 |
Correct |
131 ms |
28960 KB |
Output is correct |
6 |
Correct |
204 ms |
27292 KB |
Output is correct |
7 |
Correct |
165 ms |
34588 KB |
Output is correct |
8 |
Correct |
173 ms |
34604 KB |
Output is correct |
9 |
Correct |
100 ms |
33636 KB |
Output is correct |
10 |
Correct |
134 ms |
27120 KB |
Output is correct |
11 |
Correct |
143 ms |
26520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
172 ms |
23432 KB |
Output is correct |
3 |
Correct |
183 ms |
27692 KB |
Output is correct |
4 |
Correct |
189 ms |
27960 KB |
Output is correct |
5 |
Correct |
175 ms |
28840 KB |
Output is correct |
6 |
Correct |
165 ms |
28656 KB |
Output is correct |
7 |
Correct |
111 ms |
27820 KB |
Output is correct |
8 |
Correct |
115 ms |
31396 KB |
Output is correct |
9 |
Correct |
121 ms |
21112 KB |
Output is correct |
10 |
Correct |
151 ms |
27152 KB |
Output is correct |
11 |
Correct |
143 ms |
26572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9812 KB |
Output is correct |
4 |
Correct |
7 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9868 KB |
Output is correct |
6 |
Correct |
6 ms |
9860 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9772 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
7 ms |
9860 KB |
Output is correct |
11 |
Correct |
7 ms |
9816 KB |
Output is correct |
12 |
Correct |
7 ms |
9784 KB |
Output is correct |
13 |
Correct |
6 ms |
9864 KB |
Output is correct |
14 |
Correct |
6 ms |
9864 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Correct |
149 ms |
25428 KB |
Output is correct |
18 |
Correct |
146 ms |
28916 KB |
Output is correct |
19 |
Correct |
186 ms |
26956 KB |
Output is correct |
20 |
Correct |
154 ms |
27464 KB |
Output is correct |
21 |
Correct |
152 ms |
27568 KB |
Output is correct |
22 |
Correct |
166 ms |
29264 KB |
Output is correct |
23 |
Correct |
143 ms |
26044 KB |
Output is correct |
24 |
Correct |
104 ms |
24548 KB |
Output is correct |
25 |
Correct |
107 ms |
25828 KB |
Output is correct |
26 |
Correct |
152 ms |
27044 KB |
Output is correct |
27 |
Correct |
138 ms |
29028 KB |
Output is correct |
28 |
Correct |
142 ms |
29108 KB |
Output is correct |
29 |
Correct |
138 ms |
34564 KB |
Output is correct |
30 |
Correct |
95 ms |
33716 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
171 ms |
22740 KB |
Output is correct |
33 |
Correct |
202 ms |
27300 KB |
Output is correct |
34 |
Correct |
150 ms |
30700 KB |
Output is correct |
35 |
Correct |
131 ms |
28960 KB |
Output is correct |
36 |
Correct |
204 ms |
27292 KB |
Output is correct |
37 |
Correct |
165 ms |
34588 KB |
Output is correct |
38 |
Correct |
173 ms |
34604 KB |
Output is correct |
39 |
Correct |
100 ms |
33636 KB |
Output is correct |
40 |
Correct |
134 ms |
27120 KB |
Output is correct |
41 |
Correct |
143 ms |
26520 KB |
Output is correct |
42 |
Correct |
6 ms |
9684 KB |
Output is correct |
43 |
Correct |
172 ms |
23432 KB |
Output is correct |
44 |
Correct |
183 ms |
27692 KB |
Output is correct |
45 |
Correct |
189 ms |
27960 KB |
Output is correct |
46 |
Correct |
175 ms |
28840 KB |
Output is correct |
47 |
Correct |
165 ms |
28656 KB |
Output is correct |
48 |
Correct |
111 ms |
27820 KB |
Output is correct |
49 |
Correct |
115 ms |
31396 KB |
Output is correct |
50 |
Correct |
121 ms |
21112 KB |
Output is correct |
51 |
Correct |
151 ms |
27152 KB |
Output is correct |
52 |
Correct |
143 ms |
26572 KB |
Output is correct |
53 |
Correct |
5 ms |
9720 KB |
Output is correct |
54 |
Correct |
5 ms |
9724 KB |
Output is correct |
55 |
Correct |
5 ms |
9696 KB |
Output is correct |
56 |
Correct |
6 ms |
9860 KB |
Output is correct |
57 |
Correct |
7 ms |
9856 KB |
Output is correct |
58 |
Correct |
6 ms |
9812 KB |
Output is correct |
59 |
Correct |
6 ms |
9868 KB |
Output is correct |
60 |
Correct |
6 ms |
9812 KB |
Output is correct |
61 |
Correct |
6 ms |
9924 KB |
Output is correct |
62 |
Correct |
7 ms |
9864 KB |
Output is correct |
63 |
Correct |
6 ms |
9920 KB |
Output is correct |
64 |
Correct |
8 ms |
9812 KB |
Output is correct |
65 |
Correct |
8 ms |
9860 KB |
Output is correct |
66 |
Correct |
6 ms |
9860 KB |
Output is correct |
67 |
Correct |
158 ms |
29716 KB |
Output is correct |
68 |
Correct |
144 ms |
28784 KB |
Output is correct |
69 |
Correct |
145 ms |
27032 KB |
Output is correct |
70 |
Correct |
147 ms |
27524 KB |
Output is correct |
71 |
Correct |
144 ms |
27492 KB |
Output is correct |
72 |
Correct |
161 ms |
29184 KB |
Output is correct |
73 |
Correct |
149 ms |
26256 KB |
Output is correct |
74 |
Correct |
90 ms |
24640 KB |
Output is correct |
75 |
Correct |
93 ms |
25888 KB |
Output is correct |
76 |
Correct |
155 ms |
27080 KB |
Output is correct |
77 |
Correct |
129 ms |
28992 KB |
Output is correct |
78 |
Correct |
144 ms |
29108 KB |
Output is correct |
79 |
Correct |
179 ms |
34604 KB |
Output is correct |
80 |
Correct |
99 ms |
33672 KB |
Output is correct |
81 |
Correct |
182 ms |
27248 KB |
Output is correct |
82 |
Correct |
206 ms |
27364 KB |
Output is correct |
83 |
Correct |
155 ms |
30716 KB |
Output is correct |
84 |
Correct |
135 ms |
28988 KB |
Output is correct |
85 |
Correct |
175 ms |
27344 KB |
Output is correct |
86 |
Correct |
173 ms |
34632 KB |
Output is correct |
87 |
Correct |
161 ms |
34668 KB |
Output is correct |
88 |
Correct |
138 ms |
27280 KB |
Output is correct |
89 |
Correct |
143 ms |
26524 KB |
Output is correct |
90 |
Correct |
196 ms |
27840 KB |
Output is correct |
91 |
Correct |
194 ms |
27768 KB |
Output is correct |
92 |
Correct |
185 ms |
28000 KB |
Output is correct |
93 |
Correct |
186 ms |
28940 KB |
Output is correct |
94 |
Correct |
185 ms |
28596 KB |
Output is correct |
95 |
Correct |
115 ms |
27704 KB |
Output is correct |
96 |
Correct |
102 ms |
31416 KB |
Output is correct |
97 |
Correct |
133 ms |
21020 KB |
Output is correct |
98 |
Correct |
153 ms |
27140 KB |
Output is correct |
99 |
Correct |
145 ms |
26532 KB |
Output is correct |
100 |
Correct |
48 ms |
14028 KB |
Output is correct |
101 |
Correct |
207 ms |
27492 KB |
Output is correct |
102 |
Correct |
146 ms |
26628 KB |
Output is correct |
103 |
Correct |
185 ms |
26328 KB |
Output is correct |
104 |
Correct |
204 ms |
27608 KB |
Output is correct |