#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define int long long
using namespace std;
signed main(){
int n, m; cin >> n >> m;
vector<int> inh;
vector<vector<int>> cons; cons.resize(n);
int s;
for (int reader = 0; reader < n; ++reader) {
cin >> s;
inh.push_back(s);
}
int a, b;
for (int reader = 0; reader < m; ++reader) {
cin >> a >> b; a--; b--;
cons[a].push_back(b);
cons[b].push_back(a);
}
//vector<bool> rall (n);????????????????
vector<bool> poss; poss.resize(n, true);
vector<int> group (n); for(int i = 0; i < n; i++) group[i] = i;
vector<int> sum = inh;
vector<set<int>> isin;isin.resize(n); for(int i = 0; i < n; i++) isin[i].insert(i);
auto get = [&](int u){
int s = u;
while(group[u] != u) u = group[u];
while(group[s] != s){
int beg = group[s];
group[s] = u;
s = group[beg];
}
return u;
};
auto unite = [&](int u, int v){
u = get(u); v = get(v);
if (u==v) return;
if(isin[u].size() < isin[v].size()) swap(u, v);
group[v] = u;
sum[u] += sum[v];
for(int ins : isin[v]) isin[u].insert(ins);
};
vector<int> scanl (n); for (int i = 0; i < n; ++i) scanl[i] = i;
auto compinh = [&](int r, int s) {return inh[r] < inh[s];};
sort(scanl.begin(), scanl.end(), compinh);
for (int scanner : scanl) {
for(int c : cons[scanner]){
if(inh[c] <= inh[scanner]){
if(sum[get(c)] < inh[scanner]){
for(int killer : isin[get(c)]) poss[killer] = false;
isin[get(c)].clear();
}
unite(c, scanner);
}
}
}
for(bool printr : poss) cout << printr;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
648 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
732 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
3 ms |
780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
310 ms |
43304 KB |
Output is correct |
4 |
Correct |
386 ms |
74020 KB |
Output is correct |
5 |
Correct |
415 ms |
52028 KB |
Output is correct |
6 |
Correct |
439 ms |
54980 KB |
Output is correct |
7 |
Correct |
446 ms |
54332 KB |
Output is correct |
8 |
Correct |
505 ms |
62664 KB |
Output is correct |
9 |
Correct |
380 ms |
64048 KB |
Output is correct |
10 |
Correct |
312 ms |
38032 KB |
Output is correct |
11 |
Correct |
285 ms |
47364 KB |
Output is correct |
12 |
Correct |
439 ms |
50504 KB |
Output is correct |
13 |
Correct |
396 ms |
75068 KB |
Output is correct |
14 |
Correct |
415 ms |
72964 KB |
Output is correct |
15 |
Correct |
380 ms |
45860 KB |
Output is correct |
16 |
Correct |
283 ms |
45364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
556 ms |
60564 KB |
Output is correct |
3 |
Correct |
548 ms |
60532 KB |
Output is correct |
4 |
Correct |
479 ms |
75028 KB |
Output is correct |
5 |
Correct |
443 ms |
74656 KB |
Output is correct |
6 |
Correct |
504 ms |
60040 KB |
Output is correct |
7 |
Correct |
429 ms |
45812 KB |
Output is correct |
8 |
Correct |
421 ms |
45888 KB |
Output is correct |
9 |
Correct |
298 ms |
45380 KB |
Output is correct |
10 |
Correct |
379 ms |
50608 KB |
Output is correct |
11 |
Correct |
434 ms |
63364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
515 ms |
47496 KB |
Output is correct |
3 |
Correct |
524 ms |
51060 KB |
Output is correct |
4 |
Correct |
586 ms |
58360 KB |
Output is correct |
5 |
Correct |
687 ms |
72168 KB |
Output is correct |
6 |
Correct |
604 ms |
58412 KB |
Output is correct |
7 |
Correct |
386 ms |
47476 KB |
Output is correct |
8 |
Correct |
342 ms |
56296 KB |
Output is correct |
9 |
Correct |
293 ms |
24408 KB |
Output is correct |
10 |
Correct |
617 ms |
76728 KB |
Output is correct |
11 |
Correct |
429 ms |
64488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
648 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
732 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
3 ms |
780 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
310 ms |
43304 KB |
Output is correct |
18 |
Correct |
386 ms |
74020 KB |
Output is correct |
19 |
Correct |
415 ms |
52028 KB |
Output is correct |
20 |
Correct |
439 ms |
54980 KB |
Output is correct |
21 |
Correct |
446 ms |
54332 KB |
Output is correct |
22 |
Correct |
505 ms |
62664 KB |
Output is correct |
23 |
Correct |
380 ms |
64048 KB |
Output is correct |
24 |
Correct |
312 ms |
38032 KB |
Output is correct |
25 |
Correct |
285 ms |
47364 KB |
Output is correct |
26 |
Correct |
439 ms |
50504 KB |
Output is correct |
27 |
Correct |
396 ms |
75068 KB |
Output is correct |
28 |
Correct |
415 ms |
72964 KB |
Output is correct |
29 |
Correct |
380 ms |
45860 KB |
Output is correct |
30 |
Correct |
283 ms |
45364 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
556 ms |
60564 KB |
Output is correct |
33 |
Correct |
548 ms |
60532 KB |
Output is correct |
34 |
Correct |
479 ms |
75028 KB |
Output is correct |
35 |
Correct |
443 ms |
74656 KB |
Output is correct |
36 |
Correct |
504 ms |
60040 KB |
Output is correct |
37 |
Correct |
429 ms |
45812 KB |
Output is correct |
38 |
Correct |
421 ms |
45888 KB |
Output is correct |
39 |
Correct |
298 ms |
45380 KB |
Output is correct |
40 |
Correct |
379 ms |
50608 KB |
Output is correct |
41 |
Correct |
434 ms |
63364 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
515 ms |
47496 KB |
Output is correct |
44 |
Correct |
524 ms |
51060 KB |
Output is correct |
45 |
Correct |
586 ms |
58360 KB |
Output is correct |
46 |
Correct |
687 ms |
72168 KB |
Output is correct |
47 |
Correct |
604 ms |
58412 KB |
Output is correct |
48 |
Correct |
386 ms |
47476 KB |
Output is correct |
49 |
Correct |
342 ms |
56296 KB |
Output is correct |
50 |
Correct |
293 ms |
24408 KB |
Output is correct |
51 |
Correct |
617 ms |
76728 KB |
Output is correct |
52 |
Correct |
429 ms |
64488 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
4 ms |
668 KB |
Output is correct |
57 |
Correct |
3 ms |
724 KB |
Output is correct |
58 |
Correct |
3 ms |
596 KB |
Output is correct |
59 |
Correct |
3 ms |
596 KB |
Output is correct |
60 |
Correct |
4 ms |
500 KB |
Output is correct |
61 |
Correct |
3 ms |
724 KB |
Output is correct |
62 |
Correct |
4 ms |
776 KB |
Output is correct |
63 |
Correct |
3 ms |
732 KB |
Output is correct |
64 |
Correct |
4 ms |
724 KB |
Output is correct |
65 |
Correct |
4 ms |
852 KB |
Output is correct |
66 |
Correct |
4 ms |
724 KB |
Output is correct |
67 |
Correct |
392 ms |
43196 KB |
Output is correct |
68 |
Correct |
475 ms |
74012 KB |
Output is correct |
69 |
Correct |
563 ms |
52108 KB |
Output is correct |
70 |
Correct |
516 ms |
54908 KB |
Output is correct |
71 |
Correct |
540 ms |
54384 KB |
Output is correct |
72 |
Correct |
580 ms |
62676 KB |
Output is correct |
73 |
Correct |
411 ms |
64024 KB |
Output is correct |
74 |
Correct |
317 ms |
38004 KB |
Output is correct |
75 |
Correct |
289 ms |
47488 KB |
Output is correct |
76 |
Correct |
429 ms |
50488 KB |
Output is correct |
77 |
Correct |
415 ms |
75040 KB |
Output is correct |
78 |
Correct |
426 ms |
73008 KB |
Output is correct |
79 |
Correct |
338 ms |
45924 KB |
Output is correct |
80 |
Correct |
289 ms |
45372 KB |
Output is correct |
81 |
Correct |
525 ms |
60592 KB |
Output is correct |
82 |
Correct |
479 ms |
60556 KB |
Output is correct |
83 |
Correct |
450 ms |
75156 KB |
Output is correct |
84 |
Correct |
379 ms |
74712 KB |
Output is correct |
85 |
Correct |
461 ms |
60096 KB |
Output is correct |
86 |
Correct |
355 ms |
45860 KB |
Output is correct |
87 |
Correct |
416 ms |
45888 KB |
Output is correct |
88 |
Correct |
338 ms |
50800 KB |
Output is correct |
89 |
Correct |
388 ms |
63356 KB |
Output is correct |
90 |
Correct |
487 ms |
47504 KB |
Output is correct |
91 |
Correct |
475 ms |
51136 KB |
Output is correct |
92 |
Correct |
506 ms |
58428 KB |
Output is correct |
93 |
Correct |
583 ms |
72204 KB |
Output is correct |
94 |
Correct |
524 ms |
58428 KB |
Output is correct |
95 |
Correct |
331 ms |
47472 KB |
Output is correct |
96 |
Correct |
287 ms |
56264 KB |
Output is correct |
97 |
Correct |
264 ms |
24364 KB |
Output is correct |
98 |
Correct |
546 ms |
76712 KB |
Output is correct |
99 |
Correct |
388 ms |
64604 KB |
Output is correct |
100 |
Correct |
107 ms |
5196 KB |
Output is correct |
101 |
Correct |
494 ms |
51880 KB |
Output is correct |
102 |
Correct |
416 ms |
44896 KB |
Output is correct |
103 |
Correct |
414 ms |
36412 KB |
Output is correct |
104 |
Correct |
469 ms |
43884 KB |
Output is correct |