#include<bits/stdc++.h>
using namespace std;
#define int long long
struct graph{
int n;
vector<vector<int> > adi;
vector<int> chef;
vector<int> s;
vector<set<int> > part;
graph(int a, vector<int>& size){
n=a;
adi.resize(n);
chef.resize(n);
iota(chef.begin(), chef.end(), 0);
s.resize(n);
part.resize(n);
for(int i=0; i<n; i++){
s[i]=size[i];
part[i].insert(i);
}
}
int find(int a){
if(chef[a]==a) return a;
return chef[a]=find(chef[a]);
}
bool unite(int a, int b){
if(find(a)==find(b)){
return false;
}
if(s[find(a)]>s[find(b)]){
swap(a, b);
}
s[find(b)]+=s[find(a)];
for(auto e: part[find(a)]){
part[find(b)].insert(e);
}
chef[find(a)]=find(b);
return true;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> size(n);
vector<pair<int,int> > r(n);
for(int i=0; i<n; i++){
cin >> size[i];
r[i]={size[i], i};
}
graph g(n, size);
sort(r.begin(), r.end());
for(int i=0; i<m; i++){
int a, b;
cin >> a >> b;
g.adi[a-1].push_back(b-1);
g.adi[b-1].push_back(a-1);
}
vector<int> tin(n);
vector<bool> ans(n, true);
for(int i=0; i<n; i++){
int v=r[i].second;
tin[v]=i;
for(auto u: g.adi[v]){
if(size[u]<=size[v]){
if(g.s[g.find(u)]<size[v]){
for(auto e: g.part[g.find(u)]){
ans[e]=false;
}
g.part[g.find(u)].clear();
}
g.unite(u, v);
}
}
}
for(auto e: ans){
cout << e;
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
852 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 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 |
211 ms |
46464 KB |
Output is correct |
4 |
Correct |
225 ms |
50100 KB |
Output is correct |
5 |
Correct |
293 ms |
55172 KB |
Output is correct |
6 |
Correct |
307 ms |
58356 KB |
Output is correct |
7 |
Correct |
334 ms |
57552 KB |
Output is correct |
8 |
Correct |
350 ms |
50116 KB |
Output is correct |
9 |
Correct |
263 ms |
67148 KB |
Output is correct |
10 |
Correct |
177 ms |
41200 KB |
Output is correct |
11 |
Correct |
288 ms |
50580 KB |
Output is correct |
12 |
Correct |
279 ms |
48204 KB |
Output is correct |
13 |
Correct |
193 ms |
49040 KB |
Output is correct |
14 |
Correct |
214 ms |
48960 KB |
Output is correct |
15 |
Correct |
199 ms |
49048 KB |
Output is correct |
16 |
Correct |
150 ms |
48500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
356 ms |
63820 KB |
Output is correct |
3 |
Correct |
394 ms |
63776 KB |
Output is correct |
4 |
Correct |
225 ms |
49000 KB |
Output is correct |
5 |
Correct |
211 ms |
49020 KB |
Output is correct |
6 |
Correct |
403 ms |
63244 KB |
Output is correct |
7 |
Correct |
232 ms |
49048 KB |
Output is correct |
8 |
Correct |
249 ms |
49168 KB |
Output is correct |
9 |
Correct |
147 ms |
48488 KB |
Output is correct |
10 |
Correct |
167 ms |
39652 KB |
Output is correct |
11 |
Correct |
221 ms |
48016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
376 ms |
51000 KB |
Output is correct |
3 |
Correct |
377 ms |
54140 KB |
Output is correct |
4 |
Correct |
399 ms |
62388 KB |
Output is correct |
5 |
Correct |
484 ms |
75296 KB |
Output is correct |
6 |
Correct |
441 ms |
61620 KB |
Output is correct |
7 |
Correct |
247 ms |
50620 KB |
Output is correct |
8 |
Correct |
142 ms |
45904 KB |
Output is correct |
9 |
Correct |
195 ms |
26208 KB |
Output is correct |
10 |
Correct |
503 ms |
82636 KB |
Output is correct |
11 |
Correct |
242 ms |
47960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
852 KB |
Output is correct |
13 |
Correct |
2 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
211 ms |
46464 KB |
Output is correct |
18 |
Correct |
225 ms |
50100 KB |
Output is correct |
19 |
Correct |
293 ms |
55172 KB |
Output is correct |
20 |
Correct |
307 ms |
58356 KB |
Output is correct |
21 |
Correct |
334 ms |
57552 KB |
Output is correct |
22 |
Correct |
350 ms |
50116 KB |
Output is correct |
23 |
Correct |
263 ms |
67148 KB |
Output is correct |
24 |
Correct |
177 ms |
41200 KB |
Output is correct |
25 |
Correct |
288 ms |
50580 KB |
Output is correct |
26 |
Correct |
279 ms |
48204 KB |
Output is correct |
27 |
Correct |
193 ms |
49040 KB |
Output is correct |
28 |
Correct |
214 ms |
48960 KB |
Output is correct |
29 |
Correct |
199 ms |
49048 KB |
Output is correct |
30 |
Correct |
150 ms |
48500 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
356 ms |
63820 KB |
Output is correct |
33 |
Correct |
394 ms |
63776 KB |
Output is correct |
34 |
Correct |
225 ms |
49000 KB |
Output is correct |
35 |
Correct |
211 ms |
49020 KB |
Output is correct |
36 |
Correct |
403 ms |
63244 KB |
Output is correct |
37 |
Correct |
232 ms |
49048 KB |
Output is correct |
38 |
Correct |
249 ms |
49168 KB |
Output is correct |
39 |
Correct |
147 ms |
48488 KB |
Output is correct |
40 |
Correct |
167 ms |
39652 KB |
Output is correct |
41 |
Correct |
221 ms |
48016 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
376 ms |
51000 KB |
Output is correct |
44 |
Correct |
377 ms |
54140 KB |
Output is correct |
45 |
Correct |
399 ms |
62388 KB |
Output is correct |
46 |
Correct |
484 ms |
75296 KB |
Output is correct |
47 |
Correct |
441 ms |
61620 KB |
Output is correct |
48 |
Correct |
247 ms |
50620 KB |
Output is correct |
49 |
Correct |
142 ms |
45904 KB |
Output is correct |
50 |
Correct |
195 ms |
26208 KB |
Output is correct |
51 |
Correct |
503 ms |
82636 KB |
Output is correct |
52 |
Correct |
242 ms |
47960 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
0 ms |
212 KB |
Output is correct |
56 |
Correct |
2 ms |
596 KB |
Output is correct |
57 |
Correct |
2 ms |
724 KB |
Output is correct |
58 |
Correct |
2 ms |
724 KB |
Output is correct |
59 |
Correct |
2 ms |
596 KB |
Output is correct |
60 |
Correct |
2 ms |
596 KB |
Output is correct |
61 |
Correct |
2 ms |
724 KB |
Output is correct |
62 |
Correct |
2 ms |
852 KB |
Output is correct |
63 |
Correct |
2 ms |
724 KB |
Output is correct |
64 |
Correct |
2 ms |
852 KB |
Output is correct |
65 |
Correct |
2 ms |
724 KB |
Output is correct |
66 |
Correct |
2 ms |
724 KB |
Output is correct |
67 |
Correct |
195 ms |
46492 KB |
Output is correct |
68 |
Correct |
204 ms |
50108 KB |
Output is correct |
69 |
Correct |
336 ms |
55172 KB |
Output is correct |
70 |
Correct |
335 ms |
58304 KB |
Output is correct |
71 |
Correct |
334 ms |
57548 KB |
Output is correct |
72 |
Correct |
330 ms |
50052 KB |
Output is correct |
73 |
Correct |
286 ms |
67248 KB |
Output is correct |
74 |
Correct |
193 ms |
41148 KB |
Output is correct |
75 |
Correct |
285 ms |
50744 KB |
Output is correct |
76 |
Correct |
313 ms |
48320 KB |
Output is correct |
77 |
Correct |
190 ms |
49056 KB |
Output is correct |
78 |
Correct |
198 ms |
49052 KB |
Output is correct |
79 |
Correct |
199 ms |
48976 KB |
Output is correct |
80 |
Correct |
147 ms |
48520 KB |
Output is correct |
81 |
Correct |
369 ms |
63904 KB |
Output is correct |
82 |
Correct |
364 ms |
63780 KB |
Output is correct |
83 |
Correct |
219 ms |
49056 KB |
Output is correct |
84 |
Correct |
229 ms |
49072 KB |
Output is correct |
85 |
Correct |
357 ms |
63376 KB |
Output is correct |
86 |
Correct |
228 ms |
49040 KB |
Output is correct |
87 |
Correct |
239 ms |
49044 KB |
Output is correct |
88 |
Correct |
178 ms |
39676 KB |
Output is correct |
89 |
Correct |
215 ms |
48040 KB |
Output is correct |
90 |
Correct |
371 ms |
51024 KB |
Output is correct |
91 |
Correct |
359 ms |
54224 KB |
Output is correct |
92 |
Correct |
462 ms |
62364 KB |
Output is correct |
93 |
Correct |
493 ms |
75352 KB |
Output is correct |
94 |
Correct |
440 ms |
61632 KB |
Output is correct |
95 |
Correct |
253 ms |
50620 KB |
Output is correct |
96 |
Correct |
158 ms |
45900 KB |
Output is correct |
97 |
Correct |
233 ms |
26148 KB |
Output is correct |
98 |
Correct |
514 ms |
82752 KB |
Output is correct |
99 |
Correct |
237 ms |
48128 KB |
Output is correct |
100 |
Correct |
58 ms |
5372 KB |
Output is correct |
101 |
Correct |
393 ms |
55060 KB |
Output is correct |
102 |
Correct |
306 ms |
47340 KB |
Output is correct |
103 |
Correct |
337 ms |
38932 KB |
Output is correct |
104 |
Correct |
382 ms |
47060 KB |
Output is correct |