#include <bits/stdc++.h>
using namespace std ;
const int MAX = 2e5 + 10 ;
int arr[MAX] ;
int n , m ;
vector< vector<int> >adj(MAX) ;
int par[MAX] , sz[MAX] ;
long long val[MAX] ;
vector<int>v[MAX] ;
void init()
{
for(int i = 1 ; i <= n ; ++i)
par[i] = i , sz[i] = 1 , val[i] = arr[i] , v[i].push_back(i) ;
}
int root(int node)
{
if(par[node] == node)
return node ;
return (par[node] = root(par[node])) ;
}
void Union(int x , int y)
{
int a = root(x) ;
int b = root(y) ;
if(sz[a] < sz[b])
swap(a , b) ;
while(v[b].size())
v[a].push_back(v[b].back()) , v[b].pop_back() ;
par[b] = a ;
sz[a] += sz[b] ;
val[a] += val[b] ;
}
int mark[MAX] , ans[MAX] ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m ;
for(int i = 1 ; i <= n ; ++i)
cin>>arr[i] ;
for(int i = 0 ; i < m ; ++i)
{
int x , y ;
cin>>x>>y ;
adj[x].push_back(y) ;
adj[y].push_back(x) ;
}
vector< pair<int , int> >vp ;
for(int i = 1 ; i <= n ; ++i)
vp.emplace_back(arr[i] , i) ;
sort(vp.begin() , vp.end()) ;
init() ;
for(auto &p : vp)
{
int node = p.second ;
for(auto &child : adj[node])
{
if((!mark[child]) || root(node) == root(child))
continue ;
int r = root(child) ;
if(val[r] < arr[node])
v[r].clear() ;
Union(node , child) ;
}
mark[node] = 1 ;
}
for(auto &node : v[root(1)])
ans[node] = 1 ;
for(int i = 1 ; i <= n ; ++i)
cout<<ans[i] ;
cout<<"\n" ;
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9732 KB |
Output is correct |
4 |
Correct |
7 ms |
9940 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9868 KB |
Output is correct |
11 |
Correct |
6 ms |
9940 KB |
Output is correct |
12 |
Correct |
6 ms |
9948 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
179 ms |
31120 KB |
Output is correct |
4 |
Correct |
157 ms |
30524 KB |
Output is correct |
5 |
Correct |
180 ms |
32036 KB |
Output is correct |
6 |
Correct |
193 ms |
32792 KB |
Output is correct |
7 |
Correct |
201 ms |
32816 KB |
Output is correct |
8 |
Correct |
164 ms |
31244 KB |
Output is correct |
9 |
Correct |
161 ms |
33564 KB |
Output is correct |
10 |
Correct |
115 ms |
29408 KB |
Output is correct |
11 |
Correct |
158 ms |
31988 KB |
Output is correct |
12 |
Correct |
179 ms |
29980 KB |
Output is correct |
13 |
Correct |
145 ms |
30560 KB |
Output is correct |
14 |
Correct |
147 ms |
30492 KB |
Output is correct |
15 |
Correct |
163 ms |
31204 KB |
Output is correct |
16 |
Correct |
113 ms |
31064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
213 ms |
33460 KB |
Output is correct |
3 |
Correct |
237 ms |
36200 KB |
Output is correct |
4 |
Correct |
209 ms |
35328 KB |
Output is correct |
5 |
Correct |
155 ms |
32932 KB |
Output is correct |
6 |
Correct |
223 ms |
36848 KB |
Output is correct |
7 |
Correct |
166 ms |
34620 KB |
Output is correct |
8 |
Correct |
162 ms |
34544 KB |
Output is correct |
9 |
Correct |
98 ms |
33476 KB |
Output is correct |
10 |
Correct |
166 ms |
32044 KB |
Output is correct |
11 |
Correct |
155 ms |
33208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
205 ms |
31284 KB |
Output is correct |
3 |
Correct |
222 ms |
35900 KB |
Output is correct |
4 |
Correct |
276 ms |
34384 KB |
Output is correct |
5 |
Correct |
217 ms |
38464 KB |
Output is correct |
6 |
Correct |
282 ms |
35052 KB |
Output is correct |
7 |
Correct |
148 ms |
36316 KB |
Output is correct |
8 |
Correct |
115 ms |
33180 KB |
Output is correct |
9 |
Correct |
108 ms |
23232 KB |
Output is correct |
10 |
Correct |
205 ms |
36168 KB |
Output is correct |
11 |
Correct |
188 ms |
32260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9732 KB |
Output is correct |
4 |
Correct |
7 ms |
9940 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
7 ms |
9812 KB |
Output is correct |
9 |
Correct |
7 ms |
9940 KB |
Output is correct |
10 |
Correct |
6 ms |
9868 KB |
Output is correct |
11 |
Correct |
6 ms |
9940 KB |
Output is correct |
12 |
Correct |
6 ms |
9948 KB |
Output is correct |
13 |
Correct |
6 ms |
9940 KB |
Output is correct |
14 |
Correct |
6 ms |
9884 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
179 ms |
31120 KB |
Output is correct |
18 |
Correct |
157 ms |
30524 KB |
Output is correct |
19 |
Correct |
180 ms |
32036 KB |
Output is correct |
20 |
Correct |
193 ms |
32792 KB |
Output is correct |
21 |
Correct |
201 ms |
32816 KB |
Output is correct |
22 |
Correct |
164 ms |
31244 KB |
Output is correct |
23 |
Correct |
161 ms |
33564 KB |
Output is correct |
24 |
Correct |
115 ms |
29408 KB |
Output is correct |
25 |
Correct |
158 ms |
31988 KB |
Output is correct |
26 |
Correct |
179 ms |
29980 KB |
Output is correct |
27 |
Correct |
145 ms |
30560 KB |
Output is correct |
28 |
Correct |
147 ms |
30492 KB |
Output is correct |
29 |
Correct |
163 ms |
31204 KB |
Output is correct |
30 |
Correct |
113 ms |
31064 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
213 ms |
33460 KB |
Output is correct |
33 |
Correct |
237 ms |
36200 KB |
Output is correct |
34 |
Correct |
209 ms |
35328 KB |
Output is correct |
35 |
Correct |
155 ms |
32932 KB |
Output is correct |
36 |
Correct |
223 ms |
36848 KB |
Output is correct |
37 |
Correct |
166 ms |
34620 KB |
Output is correct |
38 |
Correct |
162 ms |
34544 KB |
Output is correct |
39 |
Correct |
98 ms |
33476 KB |
Output is correct |
40 |
Correct |
166 ms |
32044 KB |
Output is correct |
41 |
Correct |
155 ms |
33208 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
205 ms |
31284 KB |
Output is correct |
44 |
Correct |
222 ms |
35900 KB |
Output is correct |
45 |
Correct |
276 ms |
34384 KB |
Output is correct |
46 |
Correct |
217 ms |
38464 KB |
Output is correct |
47 |
Correct |
282 ms |
35052 KB |
Output is correct |
48 |
Correct |
148 ms |
36316 KB |
Output is correct |
49 |
Correct |
115 ms |
33180 KB |
Output is correct |
50 |
Correct |
108 ms |
23232 KB |
Output is correct |
51 |
Correct |
205 ms |
36168 KB |
Output is correct |
52 |
Correct |
188 ms |
32260 KB |
Output is correct |
53 |
Correct |
5 ms |
9740 KB |
Output is correct |
54 |
Correct |
5 ms |
9684 KB |
Output is correct |
55 |
Correct |
6 ms |
9684 KB |
Output is correct |
56 |
Correct |
8 ms |
9940 KB |
Output is correct |
57 |
Correct |
7 ms |
10012 KB |
Output is correct |
58 |
Correct |
7 ms |
9940 KB |
Output is correct |
59 |
Correct |
9 ms |
9888 KB |
Output is correct |
60 |
Correct |
7 ms |
9840 KB |
Output is correct |
61 |
Correct |
8 ms |
9896 KB |
Output is correct |
62 |
Correct |
8 ms |
10008 KB |
Output is correct |
63 |
Correct |
7 ms |
9936 KB |
Output is correct |
64 |
Correct |
6 ms |
9908 KB |
Output is correct |
65 |
Correct |
6 ms |
9880 KB |
Output is correct |
66 |
Correct |
7 ms |
9960 KB |
Output is correct |
67 |
Correct |
173 ms |
35080 KB |
Output is correct |
68 |
Correct |
174 ms |
33384 KB |
Output is correct |
69 |
Correct |
202 ms |
36112 KB |
Output is correct |
70 |
Correct |
203 ms |
36124 KB |
Output is correct |
71 |
Correct |
177 ms |
34244 KB |
Output is correct |
72 |
Correct |
188 ms |
34500 KB |
Output is correct |
73 |
Correct |
213 ms |
36612 KB |
Output is correct |
74 |
Correct |
118 ms |
31104 KB |
Output is correct |
75 |
Correct |
162 ms |
34080 KB |
Output is correct |
76 |
Correct |
213 ms |
31812 KB |
Output is correct |
77 |
Correct |
171 ms |
32312 KB |
Output is correct |
78 |
Correct |
162 ms |
32320 KB |
Output is correct |
79 |
Correct |
165 ms |
35004 KB |
Output is correct |
80 |
Correct |
95 ms |
34748 KB |
Output is correct |
81 |
Correct |
241 ms |
35948 KB |
Output is correct |
82 |
Correct |
215 ms |
36572 KB |
Output is correct |
83 |
Correct |
151 ms |
31336 KB |
Output is correct |
84 |
Correct |
141 ms |
32572 KB |
Output is correct |
85 |
Correct |
217 ms |
37828 KB |
Output is correct |
86 |
Correct |
163 ms |
35636 KB |
Output is correct |
87 |
Correct |
174 ms |
35548 KB |
Output is correct |
88 |
Correct |
188 ms |
31292 KB |
Output is correct |
89 |
Correct |
181 ms |
30464 KB |
Output is correct |
90 |
Correct |
236 ms |
33768 KB |
Output is correct |
91 |
Correct |
228 ms |
36064 KB |
Output is correct |
92 |
Correct |
227 ms |
37188 KB |
Output is correct |
93 |
Correct |
233 ms |
37556 KB |
Output is correct |
94 |
Correct |
209 ms |
34648 KB |
Output is correct |
95 |
Correct |
154 ms |
35572 KB |
Output is correct |
96 |
Correct |
100 ms |
32760 KB |
Output is correct |
97 |
Correct |
148 ms |
22968 KB |
Output is correct |
98 |
Correct |
191 ms |
37088 KB |
Output is correct |
99 |
Correct |
164 ms |
33044 KB |
Output is correct |
100 |
Correct |
54 ms |
13900 KB |
Output is correct |
101 |
Correct |
223 ms |
36272 KB |
Output is correct |
102 |
Correct |
159 ms |
30156 KB |
Output is correct |
103 |
Correct |
198 ms |
27412 KB |
Output is correct |
104 |
Correct |
207 ms |
31144 KB |
Output is correct |