#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=2e5+5;
ll n,m,par[mxn],s[mxn],root[mxn],sz[mxn],a[mxn];
vector<int>v[mxn],t,g[mxn];
bool ans[mxn];
bool cmp(int x,int y){
return (s[x]!=s[y])?s[x]<s[y]:x<y;
}
int fndpar(int x){
return (par[x]==x)?x:par[x]=fndpar(par[x]);
}
void dfs(int z){
ans[z]=1;
//cout<<z<<" ";
for(auto i:g[z]){
if(s[i]>=a[z])
dfs(i);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
s[i]=a[i];
t.push_back(i);
par[i]=i;
root[i]=i;
sz[i]=1;
}
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
if(s[x]>s[y] || (s[x]==s[y] && y<x))
v[x].push_back(y);
else
v[y].push_back(x);
}
sort(t.begin(),t.end(),cmp);
for(auto i:t){
//cout<<i<<'\n';
for(auto j:v[i]){
int x=fndpar(j),y=fndpar(i);
if(root[x]!=i){
//cout<<root[x]<<" ";
s[i]+=s[root[x]];
g[i].push_back(root[x]);
if(sz[x]>sz[y])swap(x,y);
par[x]=y;
sz[y]+=sz[x];
root[y]=i;
}
}
//cout<<'\n';
}
// /return 0;
dfs(t.back());
for(int i=1;i<=n;i++)
cout<<ans[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
3 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16728 KB |
Output is correct |
4 |
Correct |
4 ms |
16732 KB |
Output is correct |
5 |
Correct |
4 ms |
16988 KB |
Output is correct |
6 |
Correct |
4 ms |
16988 KB |
Output is correct |
7 |
Correct |
5 ms |
16988 KB |
Output is correct |
8 |
Correct |
4 ms |
16988 KB |
Output is correct |
9 |
Correct |
4 ms |
16988 KB |
Output is correct |
10 |
Correct |
4 ms |
16988 KB |
Output is correct |
11 |
Correct |
5 ms |
16876 KB |
Output is correct |
12 |
Correct |
4 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16880 KB |
Output is correct |
14 |
Correct |
4 ms |
16984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
3 ms |
16732 KB |
Output is correct |
3 |
Correct |
95 ms |
29412 KB |
Output is correct |
4 |
Correct |
89 ms |
34764 KB |
Output is correct |
5 |
Correct |
111 ms |
30524 KB |
Output is correct |
6 |
Correct |
117 ms |
31032 KB |
Output is correct |
7 |
Correct |
121 ms |
30964 KB |
Output is correct |
8 |
Correct |
99 ms |
40908 KB |
Output is correct |
9 |
Correct |
82 ms |
29340 KB |
Output is correct |
10 |
Correct |
70 ms |
24148 KB |
Output is correct |
11 |
Correct |
113 ms |
39992 KB |
Output is correct |
12 |
Correct |
107 ms |
33484 KB |
Output is correct |
13 |
Correct |
86 ms |
33996 KB |
Output is correct |
14 |
Correct |
103 ms |
34984 KB |
Output is correct |
15 |
Correct |
97 ms |
40912 KB |
Output is correct |
16 |
Correct |
74 ms |
39880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16872 KB |
Output is correct |
2 |
Correct |
142 ms |
26956 KB |
Output is correct |
3 |
Correct |
166 ms |
31772 KB |
Output is correct |
4 |
Correct |
122 ms |
40832 KB |
Output is correct |
5 |
Correct |
85 ms |
33988 KB |
Output is correct |
6 |
Correct |
145 ms |
31420 KB |
Output is correct |
7 |
Correct |
121 ms |
40908 KB |
Output is correct |
8 |
Correct |
127 ms |
40904 KB |
Output is correct |
9 |
Correct |
74 ms |
39912 KB |
Output is correct |
10 |
Correct |
88 ms |
31280 KB |
Output is correct |
11 |
Correct |
102 ms |
30160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
16728 KB |
Output is correct |
2 |
Correct |
164 ms |
26976 KB |
Output is correct |
3 |
Correct |
130 ms |
31184 KB |
Output is correct |
4 |
Correct |
151 ms |
31176 KB |
Output is correct |
5 |
Correct |
130 ms |
31184 KB |
Output is correct |
6 |
Correct |
113 ms |
31180 KB |
Output is correct |
7 |
Correct |
82 ms |
33596 KB |
Output is correct |
8 |
Correct |
74 ms |
37004 KB |
Output is correct |
9 |
Correct |
69 ms |
25292 KB |
Output is correct |
10 |
Correct |
93 ms |
29396 KB |
Output is correct |
11 |
Correct |
114 ms |
30156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16732 KB |
Output is correct |
2 |
Correct |
3 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16728 KB |
Output is correct |
4 |
Correct |
4 ms |
16732 KB |
Output is correct |
5 |
Correct |
4 ms |
16988 KB |
Output is correct |
6 |
Correct |
4 ms |
16988 KB |
Output is correct |
7 |
Correct |
5 ms |
16988 KB |
Output is correct |
8 |
Correct |
4 ms |
16988 KB |
Output is correct |
9 |
Correct |
4 ms |
16988 KB |
Output is correct |
10 |
Correct |
4 ms |
16988 KB |
Output is correct |
11 |
Correct |
5 ms |
16876 KB |
Output is correct |
12 |
Correct |
4 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16880 KB |
Output is correct |
14 |
Correct |
4 ms |
16984 KB |
Output is correct |
15 |
Correct |
4 ms |
16732 KB |
Output is correct |
16 |
Correct |
3 ms |
16732 KB |
Output is correct |
17 |
Correct |
95 ms |
29412 KB |
Output is correct |
18 |
Correct |
89 ms |
34764 KB |
Output is correct |
19 |
Correct |
111 ms |
30524 KB |
Output is correct |
20 |
Correct |
117 ms |
31032 KB |
Output is correct |
21 |
Correct |
121 ms |
30964 KB |
Output is correct |
22 |
Correct |
99 ms |
40908 KB |
Output is correct |
23 |
Correct |
82 ms |
29340 KB |
Output is correct |
24 |
Correct |
70 ms |
24148 KB |
Output is correct |
25 |
Correct |
113 ms |
39992 KB |
Output is correct |
26 |
Correct |
107 ms |
33484 KB |
Output is correct |
27 |
Correct |
86 ms |
33996 KB |
Output is correct |
28 |
Correct |
103 ms |
34984 KB |
Output is correct |
29 |
Correct |
97 ms |
40912 KB |
Output is correct |
30 |
Correct |
74 ms |
39880 KB |
Output is correct |
31 |
Correct |
3 ms |
16872 KB |
Output is correct |
32 |
Correct |
142 ms |
26956 KB |
Output is correct |
33 |
Correct |
166 ms |
31772 KB |
Output is correct |
34 |
Correct |
122 ms |
40832 KB |
Output is correct |
35 |
Correct |
85 ms |
33988 KB |
Output is correct |
36 |
Correct |
145 ms |
31420 KB |
Output is correct |
37 |
Correct |
121 ms |
40908 KB |
Output is correct |
38 |
Correct |
127 ms |
40904 KB |
Output is correct |
39 |
Correct |
74 ms |
39912 KB |
Output is correct |
40 |
Correct |
88 ms |
31280 KB |
Output is correct |
41 |
Correct |
102 ms |
30160 KB |
Output is correct |
42 |
Correct |
3 ms |
16728 KB |
Output is correct |
43 |
Correct |
164 ms |
26976 KB |
Output is correct |
44 |
Correct |
130 ms |
31184 KB |
Output is correct |
45 |
Correct |
151 ms |
31176 KB |
Output is correct |
46 |
Correct |
130 ms |
31184 KB |
Output is correct |
47 |
Correct |
113 ms |
31180 KB |
Output is correct |
48 |
Correct |
82 ms |
33596 KB |
Output is correct |
49 |
Correct |
74 ms |
37004 KB |
Output is correct |
50 |
Correct |
69 ms |
25292 KB |
Output is correct |
51 |
Correct |
93 ms |
29396 KB |
Output is correct |
52 |
Correct |
114 ms |
30156 KB |
Output is correct |
53 |
Correct |
3 ms |
16728 KB |
Output is correct |
54 |
Correct |
3 ms |
16732 KB |
Output is correct |
55 |
Correct |
3 ms |
16732 KB |
Output is correct |
56 |
Correct |
5 ms |
16884 KB |
Output is correct |
57 |
Correct |
4 ms |
16988 KB |
Output is correct |
58 |
Correct |
4 ms |
16988 KB |
Output is correct |
59 |
Correct |
4 ms |
16820 KB |
Output is correct |
60 |
Correct |
4 ms |
16988 KB |
Output is correct |
61 |
Correct |
4 ms |
16944 KB |
Output is correct |
62 |
Correct |
4 ms |
16988 KB |
Output is correct |
63 |
Correct |
4 ms |
16988 KB |
Output is correct |
64 |
Correct |
4 ms |
16732 KB |
Output is correct |
65 |
Correct |
4 ms |
17240 KB |
Output is correct |
66 |
Correct |
4 ms |
17240 KB |
Output is correct |
67 |
Correct |
97 ms |
33740 KB |
Output is correct |
68 |
Correct |
106 ms |
34796 KB |
Output is correct |
69 |
Correct |
101 ms |
30516 KB |
Output is correct |
70 |
Correct |
107 ms |
30876 KB |
Output is correct |
71 |
Correct |
112 ms |
30924 KB |
Output is correct |
72 |
Correct |
141 ms |
40960 KB |
Output is correct |
73 |
Correct |
90 ms |
29232 KB |
Output is correct |
74 |
Correct |
60 ms |
24372 KB |
Output is correct |
75 |
Correct |
116 ms |
39840 KB |
Output is correct |
76 |
Correct |
99 ms |
33356 KB |
Output is correct |
77 |
Correct |
95 ms |
33924 KB |
Output is correct |
78 |
Correct |
93 ms |
34764 KB |
Output is correct |
79 |
Correct |
107 ms |
41032 KB |
Output is correct |
80 |
Correct |
74 ms |
40024 KB |
Output is correct |
81 |
Correct |
137 ms |
31436 KB |
Output is correct |
82 |
Correct |
154 ms |
31588 KB |
Output is correct |
83 |
Correct |
119 ms |
40904 KB |
Output is correct |
84 |
Correct |
89 ms |
34072 KB |
Output is correct |
85 |
Correct |
144 ms |
31624 KB |
Output is correct |
86 |
Correct |
130 ms |
40904 KB |
Output is correct |
87 |
Correct |
132 ms |
40892 KB |
Output is correct |
88 |
Correct |
97 ms |
31436 KB |
Output is correct |
89 |
Correct |
102 ms |
30044 KB |
Output is correct |
90 |
Correct |
138 ms |
31436 KB |
Output is correct |
91 |
Correct |
150 ms |
31184 KB |
Output is correct |
92 |
Correct |
152 ms |
31064 KB |
Output is correct |
93 |
Correct |
153 ms |
31696 KB |
Output is correct |
94 |
Correct |
109 ms |
31184 KB |
Output is correct |
95 |
Correct |
85 ms |
33736 KB |
Output is correct |
96 |
Correct |
73 ms |
37072 KB |
Output is correct |
97 |
Correct |
66 ms |
25300 KB |
Output is correct |
98 |
Correct |
93 ms |
29388 KB |
Output is correct |
99 |
Correct |
108 ms |
30156 KB |
Output is correct |
100 |
Correct |
31 ms |
20312 KB |
Output is correct |
101 |
Correct |
153 ms |
31180 KB |
Output is correct |
102 |
Correct |
106 ms |
30424 KB |
Output is correct |
103 |
Correct |
129 ms |
30708 KB |
Output is correct |
104 |
Correct |
138 ms |
31440 KB |
Output is correct |