#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define a first
#define b second
#define pb push_back
#define endl '\n'
llo it[200001];
llo n,m;
vector<llo> adj[200001];
vector<pair<llo,llo>> adj2[200001];
llo par[200001];
llo ss[200001];
llo find(llo no){
if(par[no]==no){
return no;
}
par[no]=find(par[no]);
return par[no];
}
llo ans[200001];
void dfs(llo no,llo par=-1,llo ma=0){
ans[no]=1-ma;
for(auto j:adj2[no]){
dfs(j.a,no,max(ma,j.b));
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
vector<pair<llo,llo>> tt;
for(llo i=0;i<n;i++){
cin>>it[i];
par[i]=i;
ss[i]=it[i];
tt.pb({it[i],i});
}
for(llo i=0;i<m;i++){
llo aa,bb;
cin>>aa>>bb;
aa--;
bb--;
adj[aa].pb(bb);
adj[bb].pb(aa);
}
sort(tt.begin(),tt.end());
llo ind=0;
/*for(auto j:tt){
cout<<j.a<<",";
}
cout<<endl;*/
while(ind<tt.size()){
llo ind2=ind;
while(ind<tt.size()){
if(tt[ind].a==tt[ind2].a){
ind++;
}
else{
break;
}
}
vector<llo> ee;
for(llo i=ind2;i<ind;i++){
ee.pb(tt[i].b);
}
for(auto j:ee){
for(auto jj:adj[j]){
if(it[jj]<it[j]){
llo x=find(jj);
if(it[x]==it[j]){
llo y=find(j);
if(x!=y){
adj2[y].pb({x,0});
par[x]=y;
ss[y]+=ss[x];
}
continue;
}
llo z=0;
if(ss[x]<it[j]){
z=1;
//cout<<j<<":"<<x<<endl;
}
llo y=find(j);
if(x!=y){
adj2[y].pb({x,z});
par[x]=y;
ss[y]+=ss[x];
}
}
}
}
//cout<<ind2<<"::"<<ind<<endl;
for(auto j:ee){
for(auto jj:adj[j]){
if(j==jj){
continue;
}
if(it[jj]==it[j]){
llo x=find(j);
llo y=find(jj);
if(x==y){
continue;
}
//cout<<j<<"::"<<jj<<endl;
par[x]=y;
ss[y]+=ss[x];
adj2[y].pb({x,0});
}
}
}
}
dfs(find(0));
for(llo i=0;i<n;i++){
cout<<ans[i];
}
cout<<endl;
return 0;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:55:11: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | while(ind<tt.size()){
| ~~~^~~~~~~~~~
island.cpp:57:12: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | while(ind<tt.size()){
| ~~~^~~~~~~~~~
# |
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 |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9940 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9940 KB |
Output is correct |
7 |
Correct |
7 ms |
9956 KB |
Output is correct |
8 |
Correct |
8 ms |
9908 KB |
Output is correct |
9 |
Correct |
6 ms |
10016 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Correct |
8 ms |
9940 KB |
Output is correct |
12 |
Correct |
7 ms |
9912 KB |
Output is correct |
13 |
Correct |
7 ms |
9940 KB |
Output is correct |
14 |
Correct |
7 ms |
9940 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 |
151 ms |
35580 KB |
Output is correct |
4 |
Correct |
150 ms |
41792 KB |
Output is correct |
5 |
Correct |
230 ms |
31092 KB |
Output is correct |
6 |
Correct |
187 ms |
31820 KB |
Output is correct |
7 |
Correct |
204 ms |
31844 KB |
Output is correct |
8 |
Correct |
238 ms |
43716 KB |
Output is correct |
9 |
Correct |
147 ms |
32568 KB |
Output is correct |
10 |
Correct |
122 ms |
31516 KB |
Output is correct |
11 |
Correct |
237 ms |
44360 KB |
Output is correct |
12 |
Correct |
203 ms |
33828 KB |
Output is correct |
13 |
Correct |
156 ms |
42740 KB |
Output is correct |
14 |
Correct |
145 ms |
40952 KB |
Output is correct |
15 |
Correct |
151 ms |
41192 KB |
Output is correct |
16 |
Correct |
105 ms |
40864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
232 ms |
30548 KB |
Output is correct |
3 |
Correct |
215 ms |
30660 KB |
Output is correct |
4 |
Correct |
175 ms |
42704 KB |
Output is correct |
5 |
Correct |
146 ms |
39664 KB |
Output is correct |
6 |
Correct |
224 ms |
30672 KB |
Output is correct |
7 |
Correct |
179 ms |
41180 KB |
Output is correct |
8 |
Correct |
166 ms |
41216 KB |
Output is correct |
9 |
Correct |
104 ms |
40896 KB |
Output is correct |
10 |
Correct |
149 ms |
35732 KB |
Output is correct |
11 |
Correct |
163 ms |
31184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
231 ms |
32404 KB |
Output is correct |
3 |
Correct |
265 ms |
32068 KB |
Output is correct |
4 |
Correct |
253 ms |
31968 KB |
Output is correct |
5 |
Correct |
281 ms |
33504 KB |
Output is correct |
6 |
Correct |
238 ms |
33128 KB |
Output is correct |
7 |
Correct |
168 ms |
38700 KB |
Output is correct |
8 |
Correct |
103 ms |
43524 KB |
Output is correct |
9 |
Correct |
138 ms |
23516 KB |
Output is correct |
10 |
Correct |
245 ms |
33492 KB |
Output is correct |
11 |
Correct |
163 ms |
31168 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 |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9940 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9940 KB |
Output is correct |
7 |
Correct |
7 ms |
9956 KB |
Output is correct |
8 |
Correct |
8 ms |
9908 KB |
Output is correct |
9 |
Correct |
6 ms |
10016 KB |
Output is correct |
10 |
Correct |
7 ms |
9940 KB |
Output is correct |
11 |
Correct |
8 ms |
9940 KB |
Output is correct |
12 |
Correct |
7 ms |
9912 KB |
Output is correct |
13 |
Correct |
7 ms |
9940 KB |
Output is correct |
14 |
Correct |
7 ms |
9940 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
151 ms |
35580 KB |
Output is correct |
18 |
Correct |
150 ms |
41792 KB |
Output is correct |
19 |
Correct |
230 ms |
31092 KB |
Output is correct |
20 |
Correct |
187 ms |
31820 KB |
Output is correct |
21 |
Correct |
204 ms |
31844 KB |
Output is correct |
22 |
Correct |
238 ms |
43716 KB |
Output is correct |
23 |
Correct |
147 ms |
32568 KB |
Output is correct |
24 |
Correct |
122 ms |
31516 KB |
Output is correct |
25 |
Correct |
237 ms |
44360 KB |
Output is correct |
26 |
Correct |
203 ms |
33828 KB |
Output is correct |
27 |
Correct |
156 ms |
42740 KB |
Output is correct |
28 |
Correct |
145 ms |
40952 KB |
Output is correct |
29 |
Correct |
151 ms |
41192 KB |
Output is correct |
30 |
Correct |
105 ms |
40864 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
232 ms |
30548 KB |
Output is correct |
33 |
Correct |
215 ms |
30660 KB |
Output is correct |
34 |
Correct |
175 ms |
42704 KB |
Output is correct |
35 |
Correct |
146 ms |
39664 KB |
Output is correct |
36 |
Correct |
224 ms |
30672 KB |
Output is correct |
37 |
Correct |
179 ms |
41180 KB |
Output is correct |
38 |
Correct |
166 ms |
41216 KB |
Output is correct |
39 |
Correct |
104 ms |
40896 KB |
Output is correct |
40 |
Correct |
149 ms |
35732 KB |
Output is correct |
41 |
Correct |
163 ms |
31184 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
231 ms |
32404 KB |
Output is correct |
44 |
Correct |
265 ms |
32068 KB |
Output is correct |
45 |
Correct |
253 ms |
31968 KB |
Output is correct |
46 |
Correct |
281 ms |
33504 KB |
Output is correct |
47 |
Correct |
238 ms |
33128 KB |
Output is correct |
48 |
Correct |
168 ms |
38700 KB |
Output is correct |
49 |
Correct |
103 ms |
43524 KB |
Output is correct |
50 |
Correct |
138 ms |
23516 KB |
Output is correct |
51 |
Correct |
245 ms |
33492 KB |
Output is correct |
52 |
Correct |
163 ms |
31168 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9740 KB |
Output is correct |
55 |
Correct |
5 ms |
9684 KB |
Output is correct |
56 |
Correct |
9 ms |
9952 KB |
Output is correct |
57 |
Correct |
8 ms |
9940 KB |
Output is correct |
58 |
Correct |
6 ms |
9904 KB |
Output is correct |
59 |
Correct |
6 ms |
9940 KB |
Output is correct |
60 |
Correct |
6 ms |
9812 KB |
Output is correct |
61 |
Correct |
6 ms |
10068 KB |
Output is correct |
62 |
Correct |
6 ms |
9940 KB |
Output is correct |
63 |
Correct |
6 ms |
9940 KB |
Output is correct |
64 |
Correct |
7 ms |
9936 KB |
Output is correct |
65 |
Correct |
5 ms |
10068 KB |
Output is correct |
66 |
Correct |
6 ms |
9940 KB |
Output is correct |
67 |
Correct |
168 ms |
35552 KB |
Output is correct |
68 |
Correct |
188 ms |
41912 KB |
Output is correct |
69 |
Correct |
172 ms |
31080 KB |
Output is correct |
70 |
Correct |
197 ms |
31800 KB |
Output is correct |
71 |
Correct |
224 ms |
31884 KB |
Output is correct |
72 |
Correct |
203 ms |
43704 KB |
Output is correct |
73 |
Correct |
173 ms |
32544 KB |
Output is correct |
74 |
Correct |
165 ms |
31528 KB |
Output is correct |
75 |
Correct |
207 ms |
44344 KB |
Output is correct |
76 |
Correct |
216 ms |
33796 KB |
Output is correct |
77 |
Correct |
137 ms |
42736 KB |
Output is correct |
78 |
Correct |
148 ms |
40980 KB |
Output is correct |
79 |
Correct |
147 ms |
41120 KB |
Output is correct |
80 |
Correct |
117 ms |
40816 KB |
Output is correct |
81 |
Correct |
218 ms |
30624 KB |
Output is correct |
82 |
Correct |
217 ms |
30796 KB |
Output is correct |
83 |
Correct |
222 ms |
42676 KB |
Output is correct |
84 |
Correct |
139 ms |
39736 KB |
Output is correct |
85 |
Correct |
223 ms |
30864 KB |
Output is correct |
86 |
Correct |
196 ms |
41216 KB |
Output is correct |
87 |
Correct |
162 ms |
41128 KB |
Output is correct |
88 |
Correct |
152 ms |
35708 KB |
Output is correct |
89 |
Correct |
162 ms |
31236 KB |
Output is correct |
90 |
Correct |
271 ms |
32384 KB |
Output is correct |
91 |
Correct |
250 ms |
32092 KB |
Output is correct |
92 |
Correct |
284 ms |
31944 KB |
Output is correct |
93 |
Correct |
273 ms |
33428 KB |
Output is correct |
94 |
Correct |
219 ms |
33080 KB |
Output is correct |
95 |
Correct |
148 ms |
38684 KB |
Output is correct |
96 |
Correct |
114 ms |
43576 KB |
Output is correct |
97 |
Correct |
145 ms |
23484 KB |
Output is correct |
98 |
Correct |
223 ms |
33396 KB |
Output is correct |
99 |
Correct |
158 ms |
31188 KB |
Output is correct |
100 |
Correct |
47 ms |
14496 KB |
Output is correct |
101 |
Correct |
286 ms |
31916 KB |
Output is correct |
102 |
Correct |
197 ms |
30720 KB |
Output is correct |
103 |
Correct |
259 ms |
31180 KB |
Output is correct |
104 |
Correct |
271 ms |
32404 KB |
Output is correct |