#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
using namespace std;
const int NMAX = 200001;
class DSU{
public:
int parent[NMAX], cnt[NMAX];
long long suma[NMAX];
vector <int> comp[NMAX];
int root(int x){
if(x == parent[x])
return x;
return parent[x] = root(parent[x]);
}
void merge(int a, int b){
a = root(a);
b = root(b);
if(a == b)
return;
if(cnt[a] < cnt[b])
swap(a, b);
cnt[a] += cnt[b];
parent[b] = a;
suma[a] += suma[b];
for(auto x : comp[b])
comp[a].push_back(x);
comp[b].clear();
}
}dsu;
vector <int> v[NMAX];
int rez[NMAX];
int p[NMAX];
int idx[NMAX];
bool cmp(int a, int b){
return p[a] < p[b];
}
int main()
{
int n, m, i;
cin >> n >> m;
for(i = 1; i <= n; i++){
cin >> p[i];
rez[i] = 1;
dsu.parent[i] = i;
dsu.cnt[i] = 1;
dsu.suma[i] = p[i];
dsu.comp[i].clear();
dsu.comp[i].push_back(i);
idx[i] = i;
}
for(i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
sort(idx + 1, idx + n + 1, cmp);
for(i = 1; i <= n; i++){
int x = idx[i];
for(auto vecin : v[x]){
if(p[vecin] < p[x]){
int rV = dsu.root(vecin);
if(dsu.suma[rV] < p[x]){
for(auto y : dsu.comp[rV]){
rez[y] = 0;
}
dsu.comp[rV].clear();
}
}
if(p[vecin] <= p[x]){
dsu.merge(x, vecin);
}
}
}
for(i = 1; i <= n; i++){
cout << rez[i];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9760 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9812 KB |
Output is correct |
6 |
Correct |
8 ms |
9812 KB |
Output is correct |
7 |
Correct |
8 ms |
9824 KB |
Output is correct |
8 |
Correct |
8 ms |
9796 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Correct |
7 ms |
9940 KB |
Output is correct |
12 |
Correct |
8 ms |
9940 KB |
Output is correct |
13 |
Correct |
8 ms |
9940 KB |
Output is correct |
14 |
Correct |
8 ms |
9812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9656 KB |
Output is correct |
3 |
Correct |
291 ms |
28884 KB |
Output is correct |
4 |
Correct |
262 ms |
31692 KB |
Output is correct |
5 |
Correct |
337 ms |
30132 KB |
Output is correct |
6 |
Correct |
379 ms |
30704 KB |
Output is correct |
7 |
Correct |
359 ms |
30756 KB |
Output is correct |
8 |
Correct |
423 ms |
30400 KB |
Output is correct |
9 |
Correct |
326 ms |
32096 KB |
Output is correct |
10 |
Correct |
301 ms |
28692 KB |
Output is correct |
11 |
Correct |
231 ms |
30012 KB |
Output is correct |
12 |
Correct |
345 ms |
29584 KB |
Output is correct |
13 |
Correct |
276 ms |
32252 KB |
Output is correct |
14 |
Correct |
285 ms |
31752 KB |
Output is correct |
15 |
Correct |
291 ms |
28760 KB |
Output is correct |
16 |
Correct |
227 ms |
28600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
392 ms |
31468 KB |
Output is correct |
3 |
Correct |
376 ms |
31620 KB |
Output is correct |
4 |
Correct |
321 ms |
32292 KB |
Output is correct |
5 |
Correct |
275 ms |
32360 KB |
Output is correct |
6 |
Correct |
381 ms |
31616 KB |
Output is correct |
7 |
Correct |
315 ms |
28896 KB |
Output is correct |
8 |
Correct |
332 ms |
28872 KB |
Output is correct |
9 |
Correct |
233 ms |
28644 KB |
Output is correct |
10 |
Correct |
315 ms |
29800 KB |
Output is correct |
11 |
Correct |
311 ms |
31100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
434 ms |
29288 KB |
Output is correct |
3 |
Correct |
367 ms |
29688 KB |
Output is correct |
4 |
Correct |
424 ms |
30656 KB |
Output is correct |
5 |
Correct |
437 ms |
31588 KB |
Output is correct |
6 |
Correct |
366 ms |
29252 KB |
Output is correct |
7 |
Correct |
294 ms |
29944 KB |
Output is correct |
8 |
Correct |
234 ms |
29972 KB |
Output is correct |
9 |
Correct |
233 ms |
20344 KB |
Output is correct |
10 |
Correct |
351 ms |
32188 KB |
Output is correct |
11 |
Correct |
333 ms |
31264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9760 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
8 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9812 KB |
Output is correct |
6 |
Correct |
8 ms |
9812 KB |
Output is correct |
7 |
Correct |
8 ms |
9824 KB |
Output is correct |
8 |
Correct |
8 ms |
9796 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Correct |
7 ms |
9940 KB |
Output is correct |
12 |
Correct |
8 ms |
9940 KB |
Output is correct |
13 |
Correct |
8 ms |
9940 KB |
Output is correct |
14 |
Correct |
8 ms |
9812 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9656 KB |
Output is correct |
17 |
Correct |
291 ms |
28884 KB |
Output is correct |
18 |
Correct |
262 ms |
31692 KB |
Output is correct |
19 |
Correct |
337 ms |
30132 KB |
Output is correct |
20 |
Correct |
379 ms |
30704 KB |
Output is correct |
21 |
Correct |
359 ms |
30756 KB |
Output is correct |
22 |
Correct |
423 ms |
30400 KB |
Output is correct |
23 |
Correct |
326 ms |
32096 KB |
Output is correct |
24 |
Correct |
301 ms |
28692 KB |
Output is correct |
25 |
Correct |
231 ms |
30012 KB |
Output is correct |
26 |
Correct |
345 ms |
29584 KB |
Output is correct |
27 |
Correct |
276 ms |
32252 KB |
Output is correct |
28 |
Correct |
285 ms |
31752 KB |
Output is correct |
29 |
Correct |
291 ms |
28760 KB |
Output is correct |
30 |
Correct |
227 ms |
28600 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
392 ms |
31468 KB |
Output is correct |
33 |
Correct |
376 ms |
31620 KB |
Output is correct |
34 |
Correct |
321 ms |
32292 KB |
Output is correct |
35 |
Correct |
275 ms |
32360 KB |
Output is correct |
36 |
Correct |
381 ms |
31616 KB |
Output is correct |
37 |
Correct |
315 ms |
28896 KB |
Output is correct |
38 |
Correct |
332 ms |
28872 KB |
Output is correct |
39 |
Correct |
233 ms |
28644 KB |
Output is correct |
40 |
Correct |
315 ms |
29800 KB |
Output is correct |
41 |
Correct |
311 ms |
31100 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
434 ms |
29288 KB |
Output is correct |
44 |
Correct |
367 ms |
29688 KB |
Output is correct |
45 |
Correct |
424 ms |
30656 KB |
Output is correct |
46 |
Correct |
437 ms |
31588 KB |
Output is correct |
47 |
Correct |
366 ms |
29252 KB |
Output is correct |
48 |
Correct |
294 ms |
29944 KB |
Output is correct |
49 |
Correct |
234 ms |
29972 KB |
Output is correct |
50 |
Correct |
233 ms |
20344 KB |
Output is correct |
51 |
Correct |
351 ms |
32188 KB |
Output is correct |
52 |
Correct |
333 ms |
31264 KB |
Output is correct |
53 |
Correct |
6 ms |
9664 KB |
Output is correct |
54 |
Correct |
5 ms |
9684 KB |
Output is correct |
55 |
Correct |
6 ms |
9732 KB |
Output is correct |
56 |
Correct |
10 ms |
9812 KB |
Output is correct |
57 |
Correct |
9 ms |
9812 KB |
Output is correct |
58 |
Correct |
8 ms |
9832 KB |
Output is correct |
59 |
Correct |
8 ms |
9832 KB |
Output is correct |
60 |
Correct |
8 ms |
9812 KB |
Output is correct |
61 |
Correct |
7 ms |
9812 KB |
Output is correct |
62 |
Correct |
8 ms |
9940 KB |
Output is correct |
63 |
Correct |
11 ms |
9940 KB |
Output is correct |
64 |
Correct |
8 ms |
9896 KB |
Output is correct |
65 |
Correct |
9 ms |
9812 KB |
Output is correct |
66 |
Correct |
10 ms |
9812 KB |
Output is correct |
67 |
Correct |
364 ms |
28876 KB |
Output is correct |
68 |
Correct |
327 ms |
31832 KB |
Output is correct |
69 |
Correct |
388 ms |
30112 KB |
Output is correct |
70 |
Correct |
435 ms |
30856 KB |
Output is correct |
71 |
Correct |
388 ms |
30808 KB |
Output is correct |
72 |
Correct |
389 ms |
30468 KB |
Output is correct |
73 |
Correct |
332 ms |
31932 KB |
Output is correct |
74 |
Correct |
299 ms |
28692 KB |
Output is correct |
75 |
Correct |
274 ms |
29892 KB |
Output is correct |
76 |
Correct |
377 ms |
29728 KB |
Output is correct |
77 |
Correct |
330 ms |
32328 KB |
Output is correct |
78 |
Correct |
316 ms |
31768 KB |
Output is correct |
79 |
Correct |
329 ms |
28840 KB |
Output is correct |
80 |
Correct |
270 ms |
28632 KB |
Output is correct |
81 |
Correct |
443 ms |
31552 KB |
Output is correct |
82 |
Correct |
425 ms |
31612 KB |
Output is correct |
83 |
Correct |
381 ms |
32256 KB |
Output is correct |
84 |
Correct |
347 ms |
32372 KB |
Output is correct |
85 |
Correct |
439 ms |
31604 KB |
Output is correct |
86 |
Correct |
384 ms |
28788 KB |
Output is correct |
87 |
Correct |
390 ms |
28904 KB |
Output is correct |
88 |
Correct |
346 ms |
30036 KB |
Output is correct |
89 |
Correct |
384 ms |
31316 KB |
Output is correct |
90 |
Correct |
450 ms |
29476 KB |
Output is correct |
91 |
Correct |
524 ms |
29876 KB |
Output is correct |
92 |
Correct |
478 ms |
30728 KB |
Output is correct |
93 |
Correct |
461 ms |
31656 KB |
Output is correct |
94 |
Correct |
456 ms |
29384 KB |
Output is correct |
95 |
Correct |
328 ms |
30188 KB |
Output is correct |
96 |
Correct |
322 ms |
30140 KB |
Output is correct |
97 |
Correct |
280 ms |
20476 KB |
Output is correct |
98 |
Correct |
353 ms |
32304 KB |
Output is correct |
99 |
Correct |
329 ms |
31496 KB |
Output is correct |
100 |
Correct |
114 ms |
12392 KB |
Output is correct |
101 |
Correct |
454 ms |
30172 KB |
Output is correct |
102 |
Correct |
329 ms |
25800 KB |
Output is correct |
103 |
Correct |
376 ms |
25908 KB |
Output is correct |
104 |
Correct |
445 ms |
28868 KB |
Output is correct |