#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=2e5+5;
vector<int> adj[nax];
vector<int> newadj[nax];
int tab[nax];
int parent[nax];
long long sz[nax];
int ans[nax];
int vis[nax];
int find(int x){
if(parent[x]==x) return x;
return parent[x]=find(parent[x]);
}
bool sameset(int x,int y){
return find(x)==find(y);
}
void joinset(int x,int y){
x=find(x);
y=find(y);
parent[x]=y;
sz[y]+=sz[x];
}
bool compare(int x,int y){
if(tab[x]!=tab[y]) return tab[x]>tab[y];
else return x>y;
}
void dfs(int x,int p){
//cout <<newadj[x].size()<<endl;
for(auto u:newadj[x]){
if(u==p) continue;
if(sz[u]<tab[x]) continue;
ans[u]=1;
dfs(u,x);
}
}
int main(){
int n,m;
cin>>n>>m;
vector<pair<int,int>> cur(n);
for (int i = 0; i < n; ++i)
{
parent[i]=i;
cin>>tab[i];
sz[i]=tab[i];
cur[i]={tab[i],i};
}
for (int i = 0; i < m; ++i)
{
int x,y;
cin>>x>>y;
x--;y--;
adj[x].pb(y);
adj[y].pb(x);
}
sort(cur.begin(),cur.end());
for (int i = 0; i < n; ++i)
{
sort(adj[i].begin(),adj[i].end(),compare);
}
for (int t = 0; t < n; ++t)
{
int i=cur[t].se;
vis[i]=true;
for(auto u:adj[i]){
u=find(u);
//cout <<i<<" "<<u<<endl;
if(!vis[u]||sameset(i,u)) continue;
//cout <<i<<" "<<u<<" "<<sz[u]<<" "<<tab[i]<<endl;
if(sz[u]>=tab[i]){
newadj[i].pb(u);
}
joinset(u,i);
}
sz[i]=sz[find(i)];
}
ans[cur[n-1].se]=true;
dfs(cur[n-1].se,-1);
for (int i = 0; i < n; ++i)
{
cout <<ans[i];
}cout <<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14168 KB |
Output is correct |
2 |
Correct |
3 ms |
14172 KB |
Output is correct |
3 |
Correct |
2 ms |
14172 KB |
Output is correct |
4 |
Correct |
4 ms |
14408 KB |
Output is correct |
5 |
Correct |
5 ms |
14360 KB |
Output is correct |
6 |
Correct |
5 ms |
14424 KB |
Output is correct |
7 |
Correct |
4 ms |
14428 KB |
Output is correct |
8 |
Correct |
4 ms |
14428 KB |
Output is correct |
9 |
Correct |
4 ms |
14428 KB |
Output is correct |
10 |
Correct |
4 ms |
14428 KB |
Output is correct |
11 |
Correct |
4 ms |
14428 KB |
Output is correct |
12 |
Correct |
4 ms |
14436 KB |
Output is correct |
13 |
Correct |
4 ms |
14428 KB |
Output is correct |
14 |
Correct |
4 ms |
14264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14172 KB |
Output is correct |
2 |
Correct |
2 ms |
14172 KB |
Output is correct |
3 |
Correct |
175 ms |
31060 KB |
Output is correct |
4 |
Correct |
155 ms |
30036 KB |
Output is correct |
5 |
Correct |
164 ms |
24916 KB |
Output is correct |
6 |
Correct |
168 ms |
25256 KB |
Output is correct |
7 |
Correct |
165 ms |
25380 KB |
Output is correct |
8 |
Correct |
200 ms |
41300 KB |
Output is correct |
9 |
Correct |
159 ms |
23856 KB |
Output is correct |
10 |
Correct |
149 ms |
23240 KB |
Output is correct |
11 |
Correct |
188 ms |
42004 KB |
Output is correct |
12 |
Correct |
148 ms |
29524 KB |
Output is correct |
13 |
Correct |
137 ms |
31320 KB |
Output is correct |
14 |
Correct |
193 ms |
31060 KB |
Output is correct |
15 |
Correct |
171 ms |
41300 KB |
Output is correct |
16 |
Correct |
147 ms |
41040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
14168 KB |
Output is correct |
2 |
Correct |
178 ms |
24856 KB |
Output is correct |
3 |
Correct |
189 ms |
29264 KB |
Output is correct |
4 |
Correct |
189 ms |
45588 KB |
Output is correct |
5 |
Correct |
139 ms |
32340 KB |
Output is correct |
6 |
Correct |
193 ms |
29272 KB |
Output is correct |
7 |
Correct |
190 ms |
45604 KB |
Output is correct |
8 |
Correct |
185 ms |
45652 KB |
Output is correct |
9 |
Correct |
145 ms |
44624 KB |
Output is correct |
10 |
Correct |
151 ms |
35604 KB |
Output is correct |
11 |
Correct |
144 ms |
29264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14168 KB |
Output is correct |
2 |
Correct |
203 ms |
25936 KB |
Output is correct |
3 |
Correct |
195 ms |
29776 KB |
Output is correct |
4 |
Correct |
199 ms |
30036 KB |
Output is correct |
5 |
Correct |
225 ms |
30988 KB |
Output is correct |
6 |
Correct |
179 ms |
31940 KB |
Output is correct |
7 |
Correct |
175 ms |
38340 KB |
Output is correct |
8 |
Correct |
132 ms |
38196 KB |
Output is correct |
9 |
Correct |
128 ms |
24404 KB |
Output is correct |
10 |
Correct |
153 ms |
29476 KB |
Output is correct |
11 |
Correct |
147 ms |
29240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14168 KB |
Output is correct |
2 |
Correct |
3 ms |
14172 KB |
Output is correct |
3 |
Correct |
2 ms |
14172 KB |
Output is correct |
4 |
Correct |
4 ms |
14408 KB |
Output is correct |
5 |
Correct |
5 ms |
14360 KB |
Output is correct |
6 |
Correct |
5 ms |
14424 KB |
Output is correct |
7 |
Correct |
4 ms |
14428 KB |
Output is correct |
8 |
Correct |
4 ms |
14428 KB |
Output is correct |
9 |
Correct |
4 ms |
14428 KB |
Output is correct |
10 |
Correct |
4 ms |
14428 KB |
Output is correct |
11 |
Correct |
4 ms |
14428 KB |
Output is correct |
12 |
Correct |
4 ms |
14436 KB |
Output is correct |
13 |
Correct |
4 ms |
14428 KB |
Output is correct |
14 |
Correct |
4 ms |
14264 KB |
Output is correct |
15 |
Correct |
3 ms |
14172 KB |
Output is correct |
16 |
Correct |
2 ms |
14172 KB |
Output is correct |
17 |
Correct |
175 ms |
31060 KB |
Output is correct |
18 |
Correct |
155 ms |
30036 KB |
Output is correct |
19 |
Correct |
164 ms |
24916 KB |
Output is correct |
20 |
Correct |
168 ms |
25256 KB |
Output is correct |
21 |
Correct |
165 ms |
25380 KB |
Output is correct |
22 |
Correct |
200 ms |
41300 KB |
Output is correct |
23 |
Correct |
159 ms |
23856 KB |
Output is correct |
24 |
Correct |
149 ms |
23240 KB |
Output is correct |
25 |
Correct |
188 ms |
42004 KB |
Output is correct |
26 |
Correct |
148 ms |
29524 KB |
Output is correct |
27 |
Correct |
137 ms |
31320 KB |
Output is correct |
28 |
Correct |
193 ms |
31060 KB |
Output is correct |
29 |
Correct |
171 ms |
41300 KB |
Output is correct |
30 |
Correct |
147 ms |
41040 KB |
Output is correct |
31 |
Correct |
3 ms |
14168 KB |
Output is correct |
32 |
Correct |
178 ms |
24856 KB |
Output is correct |
33 |
Correct |
189 ms |
29264 KB |
Output is correct |
34 |
Correct |
189 ms |
45588 KB |
Output is correct |
35 |
Correct |
139 ms |
32340 KB |
Output is correct |
36 |
Correct |
193 ms |
29272 KB |
Output is correct |
37 |
Correct |
190 ms |
45604 KB |
Output is correct |
38 |
Correct |
185 ms |
45652 KB |
Output is correct |
39 |
Correct |
145 ms |
44624 KB |
Output is correct |
40 |
Correct |
151 ms |
35604 KB |
Output is correct |
41 |
Correct |
144 ms |
29264 KB |
Output is correct |
42 |
Correct |
2 ms |
14168 KB |
Output is correct |
43 |
Correct |
203 ms |
25936 KB |
Output is correct |
44 |
Correct |
195 ms |
29776 KB |
Output is correct |
45 |
Correct |
199 ms |
30036 KB |
Output is correct |
46 |
Correct |
225 ms |
30988 KB |
Output is correct |
47 |
Correct |
179 ms |
31940 KB |
Output is correct |
48 |
Correct |
175 ms |
38340 KB |
Output is correct |
49 |
Correct |
132 ms |
38196 KB |
Output is correct |
50 |
Correct |
128 ms |
24404 KB |
Output is correct |
51 |
Correct |
153 ms |
29476 KB |
Output is correct |
52 |
Correct |
147 ms |
29240 KB |
Output is correct |
53 |
Correct |
3 ms |
14168 KB |
Output is correct |
54 |
Correct |
3 ms |
14172 KB |
Output is correct |
55 |
Correct |
2 ms |
14172 KB |
Output is correct |
56 |
Correct |
6 ms |
14424 KB |
Output is correct |
57 |
Correct |
4 ms |
14472 KB |
Output is correct |
58 |
Correct |
4 ms |
14428 KB |
Output is correct |
59 |
Correct |
4 ms |
14428 KB |
Output is correct |
60 |
Correct |
4 ms |
14428 KB |
Output is correct |
61 |
Correct |
4 ms |
14428 KB |
Output is correct |
62 |
Correct |
4 ms |
14428 KB |
Output is correct |
63 |
Correct |
4 ms |
14428 KB |
Output is correct |
64 |
Correct |
4 ms |
14364 KB |
Output is correct |
65 |
Correct |
3 ms |
14428 KB |
Output is correct |
66 |
Correct |
4 ms |
14428 KB |
Output is correct |
67 |
Correct |
169 ms |
35348 KB |
Output is correct |
68 |
Correct |
140 ms |
32984 KB |
Output is correct |
69 |
Correct |
170 ms |
29012 KB |
Output is correct |
70 |
Correct |
172 ms |
29524 KB |
Output is correct |
71 |
Correct |
172 ms |
29588 KB |
Output is correct |
72 |
Correct |
190 ms |
45728 KB |
Output is correct |
73 |
Correct |
157 ms |
28132 KB |
Output is correct |
74 |
Correct |
154 ms |
26824 KB |
Output is correct |
75 |
Correct |
181 ms |
45332 KB |
Output is correct |
76 |
Correct |
148 ms |
32340 KB |
Output is correct |
77 |
Correct |
131 ms |
34132 KB |
Output is correct |
78 |
Correct |
147 ms |
34128 KB |
Output is correct |
79 |
Correct |
168 ms |
45652 KB |
Output is correct |
80 |
Correct |
148 ms |
44628 KB |
Output is correct |
81 |
Correct |
183 ms |
29268 KB |
Output is correct |
82 |
Correct |
191 ms |
29264 KB |
Output is correct |
83 |
Correct |
189 ms |
45648 KB |
Output is correct |
84 |
Correct |
130 ms |
32376 KB |
Output is correct |
85 |
Correct |
190 ms |
29268 KB |
Output is correct |
86 |
Correct |
190 ms |
45648 KB |
Output is correct |
87 |
Correct |
187 ms |
45656 KB |
Output is correct |
88 |
Correct |
165 ms |
35664 KB |
Output is correct |
89 |
Correct |
146 ms |
29056 KB |
Output is correct |
90 |
Correct |
202 ms |
30292 KB |
Output is correct |
91 |
Correct |
198 ms |
29776 KB |
Output is correct |
92 |
Correct |
198 ms |
30088 KB |
Output is correct |
93 |
Correct |
196 ms |
31060 KB |
Output is correct |
94 |
Correct |
179 ms |
31936 KB |
Output is correct |
95 |
Correct |
173 ms |
38408 KB |
Output is correct |
96 |
Correct |
132 ms |
38228 KB |
Output is correct |
97 |
Correct |
127 ms |
24404 KB |
Output is correct |
98 |
Correct |
145 ms |
29264 KB |
Output is correct |
99 |
Correct |
147 ms |
29264 KB |
Output is correct |
100 |
Correct |
81 ms |
18772 KB |
Output is correct |
101 |
Correct |
211 ms |
29712 KB |
Output is correct |
102 |
Correct |
178 ms |
31824 KB |
Output is correct |
103 |
Correct |
188 ms |
31316 KB |
Output is correct |
104 |
Correct |
199 ms |
30548 KB |
Output is correct |