#include <bits/stdc++.h>
#define IO_OP ios::sync_with_stdio(0), cin.tie(0)
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 2e5 + 7;
int s[N], where[N], ans[N], pos[N];
ll sum[N];
vi who[N], alive[N];
vi G[N];
signed main()
{
IO_OP;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> s[i];
vi p(n);
iota(ALL(p), 1);
sort(ALL(p), [&] (int a, int b) {
return s[a] < s[b];
});
for(int i = 0; i < n; i++)
pos[p[i]] = i;
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
G[u].PB(v);
G[v].PB(u);
}
auto unite = [&] (int x, int y) {
if(SZ(who[x]) > SZ(who[y])) swap(x, y);
for(int u:who[x]) {
who[y].PB(u);
where[u] = y;
}
sum[y] += sum[x];
if(SZ(alive[x]) > SZ(alive[y]))
swap(alive[x], alive[y]);
for(int u:alive[x])
alive[y].PB(u);
};
for(int u:p) {
ans[u] = 1;
where[u] = u, who[u].PB(u), alive[u].PB(u), sum[u] = s[u];
vi cc;
for(int v:G[u]) if(pos[v] < pos[u])
cc.PB(where[v]);
sort(ALL(cc));
cc.resize(unique(ALL(cc)) - cc.begin());
for(int c:cc) if(sum[c] < s[u]) {
for(int v:alive[c])
ans[v] = 0;
alive[c].clear();
}
for(int c:cc)
unite(where[u], c);
}
for(int i = 1; i <= n; i++)
cout << ans[i];
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
14436 KB |
Output is correct |
2 |
Correct |
10 ms |
14400 KB |
Output is correct |
3 |
Correct |
9 ms |
14420 KB |
Output is correct |
4 |
Correct |
13 ms |
14696 KB |
Output is correct |
5 |
Correct |
12 ms |
14628 KB |
Output is correct |
6 |
Correct |
10 ms |
14572 KB |
Output is correct |
7 |
Correct |
10 ms |
14660 KB |
Output is correct |
8 |
Correct |
9 ms |
14548 KB |
Output is correct |
9 |
Correct |
10 ms |
14676 KB |
Output is correct |
10 |
Correct |
11 ms |
14676 KB |
Output is correct |
11 |
Correct |
10 ms |
14732 KB |
Output is correct |
12 |
Correct |
9 ms |
14648 KB |
Output is correct |
13 |
Correct |
10 ms |
14676 KB |
Output is correct |
14 |
Correct |
10 ms |
14732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
9 ms |
14420 KB |
Output is correct |
3 |
Correct |
219 ms |
40568 KB |
Output is correct |
4 |
Correct |
191 ms |
46276 KB |
Output is correct |
5 |
Correct |
297 ms |
44688 KB |
Output is correct |
6 |
Correct |
276 ms |
46500 KB |
Output is correct |
7 |
Correct |
308 ms |
46096 KB |
Output is correct |
8 |
Correct |
242 ms |
43244 KB |
Output is correct |
9 |
Correct |
207 ms |
50816 KB |
Output is correct |
10 |
Correct |
173 ms |
42384 KB |
Output is correct |
11 |
Correct |
161 ms |
42928 KB |
Output is correct |
12 |
Correct |
286 ms |
43732 KB |
Output is correct |
13 |
Correct |
241 ms |
48476 KB |
Output is correct |
14 |
Correct |
189 ms |
47528 KB |
Output is correct |
15 |
Correct |
187 ms |
41164 KB |
Output is correct |
16 |
Correct |
114 ms |
41252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
391 ms |
48408 KB |
Output is correct |
3 |
Correct |
342 ms |
48176 KB |
Output is correct |
4 |
Correct |
224 ms |
48732 KB |
Output is correct |
5 |
Correct |
191 ms |
48564 KB |
Output is correct |
6 |
Correct |
371 ms |
49208 KB |
Output is correct |
7 |
Correct |
190 ms |
41448 KB |
Output is correct |
8 |
Correct |
186 ms |
41444 KB |
Output is correct |
9 |
Correct |
131 ms |
41204 KB |
Output is correct |
10 |
Correct |
245 ms |
45888 KB |
Output is correct |
11 |
Correct |
285 ms |
47384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
406 ms |
42592 KB |
Output is correct |
3 |
Correct |
453 ms |
44604 KB |
Output is correct |
4 |
Correct |
411 ms |
45668 KB |
Output is correct |
5 |
Correct |
322 ms |
46436 KB |
Output is correct |
6 |
Correct |
243 ms |
42344 KB |
Output is correct |
7 |
Correct |
215 ms |
42164 KB |
Output is correct |
8 |
Correct |
185 ms |
44532 KB |
Output is correct |
9 |
Correct |
188 ms |
30088 KB |
Output is correct |
10 |
Correct |
326 ms |
47844 KB |
Output is correct |
11 |
Correct |
308 ms |
47468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
14436 KB |
Output is correct |
2 |
Correct |
10 ms |
14400 KB |
Output is correct |
3 |
Correct |
9 ms |
14420 KB |
Output is correct |
4 |
Correct |
13 ms |
14696 KB |
Output is correct |
5 |
Correct |
12 ms |
14628 KB |
Output is correct |
6 |
Correct |
10 ms |
14572 KB |
Output is correct |
7 |
Correct |
10 ms |
14660 KB |
Output is correct |
8 |
Correct |
9 ms |
14548 KB |
Output is correct |
9 |
Correct |
10 ms |
14676 KB |
Output is correct |
10 |
Correct |
11 ms |
14676 KB |
Output is correct |
11 |
Correct |
10 ms |
14732 KB |
Output is correct |
12 |
Correct |
9 ms |
14648 KB |
Output is correct |
13 |
Correct |
10 ms |
14676 KB |
Output is correct |
14 |
Correct |
10 ms |
14732 KB |
Output is correct |
15 |
Correct |
9 ms |
14420 KB |
Output is correct |
16 |
Correct |
9 ms |
14420 KB |
Output is correct |
17 |
Correct |
219 ms |
40568 KB |
Output is correct |
18 |
Correct |
191 ms |
46276 KB |
Output is correct |
19 |
Correct |
297 ms |
44688 KB |
Output is correct |
20 |
Correct |
276 ms |
46500 KB |
Output is correct |
21 |
Correct |
308 ms |
46096 KB |
Output is correct |
22 |
Correct |
242 ms |
43244 KB |
Output is correct |
23 |
Correct |
207 ms |
50816 KB |
Output is correct |
24 |
Correct |
173 ms |
42384 KB |
Output is correct |
25 |
Correct |
161 ms |
42928 KB |
Output is correct |
26 |
Correct |
286 ms |
43732 KB |
Output is correct |
27 |
Correct |
241 ms |
48476 KB |
Output is correct |
28 |
Correct |
189 ms |
47528 KB |
Output is correct |
29 |
Correct |
187 ms |
41164 KB |
Output is correct |
30 |
Correct |
114 ms |
41252 KB |
Output is correct |
31 |
Correct |
9 ms |
14420 KB |
Output is correct |
32 |
Correct |
391 ms |
48408 KB |
Output is correct |
33 |
Correct |
342 ms |
48176 KB |
Output is correct |
34 |
Correct |
224 ms |
48732 KB |
Output is correct |
35 |
Correct |
191 ms |
48564 KB |
Output is correct |
36 |
Correct |
371 ms |
49208 KB |
Output is correct |
37 |
Correct |
190 ms |
41448 KB |
Output is correct |
38 |
Correct |
186 ms |
41444 KB |
Output is correct |
39 |
Correct |
131 ms |
41204 KB |
Output is correct |
40 |
Correct |
245 ms |
45888 KB |
Output is correct |
41 |
Correct |
285 ms |
47384 KB |
Output is correct |
42 |
Correct |
8 ms |
14420 KB |
Output is correct |
43 |
Correct |
406 ms |
42592 KB |
Output is correct |
44 |
Correct |
453 ms |
44604 KB |
Output is correct |
45 |
Correct |
411 ms |
45668 KB |
Output is correct |
46 |
Correct |
322 ms |
46436 KB |
Output is correct |
47 |
Correct |
243 ms |
42344 KB |
Output is correct |
48 |
Correct |
215 ms |
42164 KB |
Output is correct |
49 |
Correct |
185 ms |
44532 KB |
Output is correct |
50 |
Correct |
188 ms |
30088 KB |
Output is correct |
51 |
Correct |
326 ms |
47844 KB |
Output is correct |
52 |
Correct |
308 ms |
47468 KB |
Output is correct |
53 |
Correct |
7 ms |
14420 KB |
Output is correct |
54 |
Correct |
9 ms |
14420 KB |
Output is correct |
55 |
Correct |
10 ms |
14420 KB |
Output is correct |
56 |
Correct |
9 ms |
14688 KB |
Output is correct |
57 |
Correct |
9 ms |
14696 KB |
Output is correct |
58 |
Correct |
9 ms |
14640 KB |
Output is correct |
59 |
Correct |
11 ms |
14612 KB |
Output is correct |
60 |
Correct |
11 ms |
14548 KB |
Output is correct |
61 |
Correct |
11 ms |
14676 KB |
Output is correct |
62 |
Correct |
12 ms |
14676 KB |
Output is correct |
63 |
Correct |
10 ms |
14632 KB |
Output is correct |
64 |
Correct |
9 ms |
14676 KB |
Output is correct |
65 |
Correct |
10 ms |
14676 KB |
Output is correct |
66 |
Correct |
11 ms |
14676 KB |
Output is correct |
67 |
Correct |
206 ms |
41564 KB |
Output is correct |
68 |
Correct |
232 ms |
47244 KB |
Output is correct |
69 |
Correct |
294 ms |
45048 KB |
Output is correct |
70 |
Correct |
328 ms |
46504 KB |
Output is correct |
71 |
Correct |
293 ms |
45936 KB |
Output is correct |
72 |
Correct |
339 ms |
43264 KB |
Output is correct |
73 |
Correct |
234 ms |
50820 KB |
Output is correct |
74 |
Correct |
173 ms |
42756 KB |
Output is correct |
75 |
Correct |
190 ms |
43644 KB |
Output is correct |
76 |
Correct |
271 ms |
43808 KB |
Output is correct |
77 |
Correct |
227 ms |
48388 KB |
Output is correct |
78 |
Correct |
186 ms |
47616 KB |
Output is correct |
79 |
Correct |
177 ms |
41500 KB |
Output is correct |
80 |
Correct |
134 ms |
41180 KB |
Output is correct |
81 |
Correct |
363 ms |
49452 KB |
Output is correct |
82 |
Correct |
359 ms |
49220 KB |
Output is correct |
83 |
Correct |
218 ms |
47708 KB |
Output is correct |
84 |
Correct |
199 ms |
48512 KB |
Output is correct |
85 |
Correct |
395 ms |
49180 KB |
Output is correct |
86 |
Correct |
189 ms |
41372 KB |
Output is correct |
87 |
Correct |
223 ms |
41408 KB |
Output is correct |
88 |
Correct |
210 ms |
45044 KB |
Output is correct |
89 |
Correct |
322 ms |
46512 KB |
Output is correct |
90 |
Correct |
373 ms |
42604 KB |
Output is correct |
91 |
Correct |
402 ms |
44648 KB |
Output is correct |
92 |
Correct |
411 ms |
46024 KB |
Output is correct |
93 |
Correct |
278 ms |
46404 KB |
Output is correct |
94 |
Correct |
246 ms |
42412 KB |
Output is correct |
95 |
Correct |
152 ms |
42260 KB |
Output is correct |
96 |
Correct |
138 ms |
44600 KB |
Output is correct |
97 |
Correct |
155 ms |
29452 KB |
Output is correct |
98 |
Correct |
284 ms |
46960 KB |
Output is correct |
99 |
Correct |
257 ms |
47536 KB |
Output is correct |
100 |
Correct |
59 ms |
17856 KB |
Output is correct |
101 |
Correct |
434 ms |
45460 KB |
Output is correct |
102 |
Correct |
221 ms |
36660 KB |
Output is correct |
103 |
Correct |
280 ms |
36660 KB |
Output is correct |
104 |
Correct |
478 ms |
41644 KB |
Output is correct |