#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p2;
typedef tuple<int,int,int> t3;
const int N=2e5+5;
int n,m;
int s[2*N],fa[2*N],ans[2*N];
ll sz[2*N];
vector<t3> edge;
vector<p2> node;
int fp(int u){
if(u==fa[u])return u;
return fa[u]=fp(fa[u]);
}
void dfs(int u){
if(u<=n)return;
auto [l,r]=node[u];
if(ans[u]==0)ans[l]=ans[r]=0;
dfs(l);
dfs(r);
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
for(int i=1;i<=n;i++)cin >> s[i];
for(int i=1;i<=2*n;i++){
fa[i]=i;
sz[i]=s[i];
ans[i]=1;
}
for(int i=0;i<m;i++){
int u,v;
cin >> u >> v;
edge.emplace_back(max(s[u],s[v]),u,v);
}
sort(edge.begin(),edge.end());
node=vector<p2>(n+1,p2(0,0));
for(auto [w,u,v]:edge){
int pu=fp(u),pv=fp(v);
if(pu==pv)continue;
if(sz[pu]<w)ans[pu]=0;
if(sz[pv]<w)ans[pv]=0;
int p=node.size();
node.emplace_back(pu,pv);
fa[pu]=fa[pv]=p;
sz[p]=sz[pu]+sz[pv];
}
for(int i=2;i<=n;i++)if(fp(i)!=fp(1))cout << string(n,'0'),exit(0);
dfs(node.size()-1);
for(int i=1;i<=n;i++)cout << ans[i];
}
Compilation message
island.cpp: In function 'void dfs(int)':
island.cpp:25:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
25 | auto [l,r]=node[u];
| ^
island.cpp: In function 'int main()':
island.cpp:47:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for(auto [w,u,v]:edge){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
80 ms |
14492 KB |
Output is correct |
4 |
Correct |
73 ms |
15956 KB |
Output is correct |
5 |
Correct |
83 ms |
18300 KB |
Output is correct |
6 |
Correct |
82 ms |
17448 KB |
Output is correct |
7 |
Correct |
98 ms |
17508 KB |
Output is correct |
8 |
Correct |
87 ms |
20644 KB |
Output is correct |
9 |
Correct |
79 ms |
17504 KB |
Output is correct |
10 |
Correct |
70 ms |
19896 KB |
Output is correct |
11 |
Correct |
68 ms |
19604 KB |
Output is correct |
12 |
Correct |
77 ms |
16704 KB |
Output is correct |
13 |
Correct |
67 ms |
19140 KB |
Output is correct |
14 |
Correct |
69 ms |
19056 KB |
Output is correct |
15 |
Correct |
72 ms |
20716 KB |
Output is correct |
16 |
Correct |
55 ms |
19820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
82 ms |
13072 KB |
Output is correct |
3 |
Correct |
84 ms |
15356 KB |
Output is correct |
4 |
Correct |
75 ms |
18604 KB |
Output is correct |
5 |
Correct |
67 ms |
17504 KB |
Output is correct |
6 |
Correct |
82 ms |
15364 KB |
Output is correct |
7 |
Correct |
73 ms |
18584 KB |
Output is correct |
8 |
Correct |
83 ms |
18528 KB |
Output is correct |
9 |
Correct |
56 ms |
18512 KB |
Output is correct |
10 |
Correct |
73 ms |
18516 KB |
Output is correct |
11 |
Correct |
73 ms |
16516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
91 ms |
13268 KB |
Output is correct |
3 |
Correct |
90 ms |
17548 KB |
Output is correct |
4 |
Correct |
89 ms |
17588 KB |
Output is correct |
5 |
Correct |
83 ms |
17540 KB |
Output is correct |
6 |
Correct |
82 ms |
18612 KB |
Output is correct |
7 |
Correct |
80 ms |
20696 KB |
Output is correct |
8 |
Correct |
66 ms |
19556 KB |
Output is correct |
9 |
Correct |
64 ms |
11432 KB |
Output is correct |
10 |
Correct |
78 ms |
16068 KB |
Output is correct |
11 |
Correct |
81 ms |
17076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
80 ms |
14492 KB |
Output is correct |
18 |
Correct |
73 ms |
15956 KB |
Output is correct |
19 |
Correct |
83 ms |
18300 KB |
Output is correct |
20 |
Correct |
82 ms |
17448 KB |
Output is correct |
21 |
Correct |
98 ms |
17508 KB |
Output is correct |
22 |
Correct |
87 ms |
20644 KB |
Output is correct |
23 |
Correct |
79 ms |
17504 KB |
Output is correct |
24 |
Correct |
70 ms |
19896 KB |
Output is correct |
25 |
Correct |
68 ms |
19604 KB |
Output is correct |
26 |
Correct |
77 ms |
16704 KB |
Output is correct |
27 |
Correct |
67 ms |
19140 KB |
Output is correct |
28 |
Correct |
69 ms |
19056 KB |
Output is correct |
29 |
Correct |
72 ms |
20716 KB |
Output is correct |
30 |
Correct |
55 ms |
19820 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
82 ms |
13072 KB |
Output is correct |
33 |
Correct |
84 ms |
15356 KB |
Output is correct |
34 |
Correct |
75 ms |
18604 KB |
Output is correct |
35 |
Correct |
67 ms |
17504 KB |
Output is correct |
36 |
Correct |
82 ms |
15364 KB |
Output is correct |
37 |
Correct |
73 ms |
18584 KB |
Output is correct |
38 |
Correct |
83 ms |
18528 KB |
Output is correct |
39 |
Correct |
56 ms |
18512 KB |
Output is correct |
40 |
Correct |
73 ms |
18516 KB |
Output is correct |
41 |
Correct |
73 ms |
16516 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
91 ms |
13268 KB |
Output is correct |
44 |
Correct |
90 ms |
17548 KB |
Output is correct |
45 |
Correct |
89 ms |
17588 KB |
Output is correct |
46 |
Correct |
83 ms |
17540 KB |
Output is correct |
47 |
Correct |
82 ms |
18612 KB |
Output is correct |
48 |
Correct |
80 ms |
20696 KB |
Output is correct |
49 |
Correct |
66 ms |
19556 KB |
Output is correct |
50 |
Correct |
64 ms |
11432 KB |
Output is correct |
51 |
Correct |
78 ms |
16068 KB |
Output is correct |
52 |
Correct |
81 ms |
17076 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
0 ms |
320 KB |
Output is correct |
55 |
Correct |
0 ms |
324 KB |
Output is correct |
56 |
Correct |
1 ms |
468 KB |
Output is correct |
57 |
Correct |
1 ms |
468 KB |
Output is correct |
58 |
Correct |
1 ms |
468 KB |
Output is correct |
59 |
Correct |
1 ms |
468 KB |
Output is correct |
60 |
Correct |
1 ms |
468 KB |
Output is correct |
61 |
Correct |
1 ms |
468 KB |
Output is correct |
62 |
Correct |
1 ms |
468 KB |
Output is correct |
63 |
Correct |
1 ms |
468 KB |
Output is correct |
64 |
Correct |
1 ms |
464 KB |
Output is correct |
65 |
Correct |
1 ms |
468 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
77 ms |
18992 KB |
Output is correct |
68 |
Correct |
85 ms |
19008 KB |
Output is correct |
69 |
Correct |
83 ms |
18352 KB |
Output is correct |
70 |
Correct |
80 ms |
17508 KB |
Output is correct |
71 |
Correct |
79 ms |
17520 KB |
Output is correct |
72 |
Correct |
84 ms |
20588 KB |
Output is correct |
73 |
Correct |
78 ms |
17480 KB |
Output is correct |
74 |
Correct |
70 ms |
19812 KB |
Output is correct |
75 |
Correct |
70 ms |
19608 KB |
Output is correct |
76 |
Correct |
76 ms |
16788 KB |
Output is correct |
77 |
Correct |
67 ms |
19216 KB |
Output is correct |
78 |
Correct |
68 ms |
18968 KB |
Output is correct |
79 |
Correct |
74 ms |
20700 KB |
Output is correct |
80 |
Correct |
55 ms |
19780 KB |
Output is correct |
81 |
Correct |
83 ms |
17440 KB |
Output is correct |
82 |
Correct |
91 ms |
17592 KB |
Output is correct |
83 |
Correct |
74 ms |
20728 KB |
Output is correct |
84 |
Correct |
73 ms |
18120 KB |
Output is correct |
85 |
Correct |
82 ms |
17624 KB |
Output is correct |
86 |
Correct |
77 ms |
20676 KB |
Output is correct |
87 |
Correct |
75 ms |
20680 KB |
Output is correct |
88 |
Correct |
76 ms |
19992 KB |
Output is correct |
89 |
Correct |
73 ms |
17156 KB |
Output is correct |
90 |
Correct |
92 ms |
17736 KB |
Output is correct |
91 |
Correct |
94 ms |
17560 KB |
Output is correct |
92 |
Correct |
107 ms |
17572 KB |
Output is correct |
93 |
Correct |
86 ms |
17644 KB |
Output is correct |
94 |
Correct |
86 ms |
18688 KB |
Output is correct |
95 |
Correct |
82 ms |
20616 KB |
Output is correct |
96 |
Correct |
64 ms |
19484 KB |
Output is correct |
97 |
Correct |
63 ms |
11320 KB |
Output is correct |
98 |
Correct |
76 ms |
16076 KB |
Output is correct |
99 |
Correct |
77 ms |
17176 KB |
Output is correct |
100 |
Correct |
47 ms |
5008 KB |
Output is correct |
101 |
Correct |
89 ms |
17672 KB |
Output is correct |
102 |
Correct |
79 ms |
16672 KB |
Output is correct |
103 |
Correct |
84 ms |
17780 KB |
Output is correct |
104 |
Correct |
88 ms |
19168 KB |
Output is correct |