#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,tag[200010],subsum[200010],dsu[200010],ans[200010];
vector<ll> e[200010],te[200010];
pair<ll,ll> val[200010];
int f(int a){
if(dsu[a]!=a){
dsu[a]=f(dsu[a]);
return dsu[a];
}else{
return a;
}
}
void dfs(int now,int x){
tag[now]==1?ans[now]=0:ans[now]=x;
for(auto ne:te[now]){
dfs(ne,ans[now]);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>val[i].first;
val[i].second=i;
dsu[i]=i;
subsum[i]=val[i].first;
}
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
if(a>b)swap(a,b);
if(val[a].first>val[b].first)e[a].push_back(b);
else e[b].push_back(a);
}
sort(&val[1],&val[n+1]);
for(int i=1;i<=n;i++){
ll x=val[i].second;
ll y=val[i].first;
for(auto ne:e[x]){
ne=f(ne);
if(ne==x)continue;
te[x].push_back(ne);
if(subsum[ne]<y)tag[ne]=1;
dsu[ne]=x;
subsum[x]+=subsum[ne];
}
}
dfs(val[n].second,1);
for(int i=1;i<=n;i++)cout<<ans[i];
cout<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9624 KB |
Output is correct |
2 |
Correct |
5 ms |
9728 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9812 KB |
Output is correct |
7 |
Correct |
5 ms |
9880 KB |
Output is correct |
8 |
Correct |
5 ms |
9812 KB |
Output is correct |
9 |
Correct |
4 ms |
9996 KB |
Output is correct |
10 |
Correct |
5 ms |
9940 KB |
Output is correct |
11 |
Correct |
5 ms |
9940 KB |
Output is correct |
12 |
Correct |
5 ms |
9876 KB |
Output is correct |
13 |
Correct |
5 ms |
10068 KB |
Output is correct |
14 |
Correct |
5 ms |
9940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
110 ms |
33144 KB |
Output is correct |
4 |
Correct |
109 ms |
39904 KB |
Output is correct |
5 |
Correct |
108 ms |
31124 KB |
Output is correct |
6 |
Correct |
123 ms |
31720 KB |
Output is correct |
7 |
Correct |
112 ms |
31820 KB |
Output is correct |
8 |
Correct |
116 ms |
43980 KB |
Output is correct |
9 |
Correct |
84 ms |
29124 KB |
Output is correct |
10 |
Correct |
62 ms |
26112 KB |
Output is correct |
11 |
Correct |
106 ms |
42956 KB |
Output is correct |
12 |
Correct |
120 ms |
34344 KB |
Output is correct |
13 |
Correct |
90 ms |
42440 KB |
Output is correct |
14 |
Correct |
92 ms |
41676 KB |
Output is correct |
15 |
Correct |
98 ms |
44016 KB |
Output is correct |
16 |
Correct |
71 ms |
43028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
157 ms |
28784 KB |
Output is correct |
3 |
Correct |
162 ms |
28904 KB |
Output is correct |
4 |
Correct |
117 ms |
40852 KB |
Output is correct |
5 |
Correct |
90 ms |
37808 KB |
Output is correct |
6 |
Correct |
143 ms |
28940 KB |
Output is correct |
7 |
Correct |
135 ms |
40808 KB |
Output is correct |
8 |
Correct |
112 ms |
40908 KB |
Output is correct |
9 |
Correct |
71 ms |
40508 KB |
Output is correct |
10 |
Correct |
95 ms |
31404 KB |
Output is correct |
11 |
Correct |
112 ms |
30672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
166 ms |
29532 KB |
Output is correct |
3 |
Correct |
150 ms |
32156 KB |
Output is correct |
4 |
Correct |
181 ms |
32180 KB |
Output is correct |
5 |
Correct |
145 ms |
30696 KB |
Output is correct |
6 |
Correct |
112 ms |
30996 KB |
Output is correct |
7 |
Correct |
90 ms |
35604 KB |
Output is correct |
8 |
Correct |
74 ms |
42932 KB |
Output is correct |
9 |
Correct |
80 ms |
23524 KB |
Output is correct |
10 |
Correct |
116 ms |
29088 KB |
Output is correct |
11 |
Correct |
108 ms |
32388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9624 KB |
Output is correct |
2 |
Correct |
5 ms |
9728 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Correct |
5 ms |
9812 KB |
Output is correct |
7 |
Correct |
5 ms |
9880 KB |
Output is correct |
8 |
Correct |
5 ms |
9812 KB |
Output is correct |
9 |
Correct |
4 ms |
9996 KB |
Output is correct |
10 |
Correct |
5 ms |
9940 KB |
Output is correct |
11 |
Correct |
5 ms |
9940 KB |
Output is correct |
12 |
Correct |
5 ms |
9876 KB |
Output is correct |
13 |
Correct |
5 ms |
10068 KB |
Output is correct |
14 |
Correct |
5 ms |
9940 KB |
Output is correct |
15 |
Correct |
4 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
110 ms |
33144 KB |
Output is correct |
18 |
Correct |
109 ms |
39904 KB |
Output is correct |
19 |
Correct |
108 ms |
31124 KB |
Output is correct |
20 |
Correct |
123 ms |
31720 KB |
Output is correct |
21 |
Correct |
112 ms |
31820 KB |
Output is correct |
22 |
Correct |
116 ms |
43980 KB |
Output is correct |
23 |
Correct |
84 ms |
29124 KB |
Output is correct |
24 |
Correct |
62 ms |
26112 KB |
Output is correct |
25 |
Correct |
106 ms |
42956 KB |
Output is correct |
26 |
Correct |
120 ms |
34344 KB |
Output is correct |
27 |
Correct |
90 ms |
42440 KB |
Output is correct |
28 |
Correct |
92 ms |
41676 KB |
Output is correct |
29 |
Correct |
98 ms |
44016 KB |
Output is correct |
30 |
Correct |
71 ms |
43028 KB |
Output is correct |
31 |
Correct |
4 ms |
9684 KB |
Output is correct |
32 |
Correct |
157 ms |
28784 KB |
Output is correct |
33 |
Correct |
162 ms |
28904 KB |
Output is correct |
34 |
Correct |
117 ms |
40852 KB |
Output is correct |
35 |
Correct |
90 ms |
37808 KB |
Output is correct |
36 |
Correct |
143 ms |
28940 KB |
Output is correct |
37 |
Correct |
135 ms |
40808 KB |
Output is correct |
38 |
Correct |
112 ms |
40908 KB |
Output is correct |
39 |
Correct |
71 ms |
40508 KB |
Output is correct |
40 |
Correct |
95 ms |
31404 KB |
Output is correct |
41 |
Correct |
112 ms |
30672 KB |
Output is correct |
42 |
Correct |
4 ms |
9684 KB |
Output is correct |
43 |
Correct |
166 ms |
29532 KB |
Output is correct |
44 |
Correct |
150 ms |
32156 KB |
Output is correct |
45 |
Correct |
181 ms |
32180 KB |
Output is correct |
46 |
Correct |
145 ms |
30696 KB |
Output is correct |
47 |
Correct |
112 ms |
30996 KB |
Output is correct |
48 |
Correct |
90 ms |
35604 KB |
Output is correct |
49 |
Correct |
74 ms |
42932 KB |
Output is correct |
50 |
Correct |
80 ms |
23524 KB |
Output is correct |
51 |
Correct |
116 ms |
29088 KB |
Output is correct |
52 |
Correct |
108 ms |
32388 KB |
Output is correct |
53 |
Correct |
4 ms |
9684 KB |
Output is correct |
54 |
Correct |
4 ms |
9684 KB |
Output is correct |
55 |
Correct |
4 ms |
9684 KB |
Output is correct |
56 |
Correct |
5 ms |
9940 KB |
Output is correct |
57 |
Correct |
6 ms |
9872 KB |
Output is correct |
58 |
Correct |
5 ms |
9848 KB |
Output is correct |
59 |
Correct |
5 ms |
9940 KB |
Output is correct |
60 |
Correct |
5 ms |
9872 KB |
Output is correct |
61 |
Correct |
5 ms |
10068 KB |
Output is correct |
62 |
Correct |
5 ms |
9956 KB |
Output is correct |
63 |
Correct |
5 ms |
9940 KB |
Output is correct |
64 |
Correct |
5 ms |
9940 KB |
Output is correct |
65 |
Correct |
6 ms |
10004 KB |
Output is correct |
66 |
Correct |
5 ms |
9844 KB |
Output is correct |
67 |
Correct |
97 ms |
36352 KB |
Output is correct |
68 |
Correct |
96 ms |
41684 KB |
Output is correct |
69 |
Correct |
105 ms |
31124 KB |
Output is correct |
70 |
Correct |
108 ms |
31712 KB |
Output is correct |
71 |
Correct |
128 ms |
31808 KB |
Output is correct |
72 |
Correct |
131 ms |
44032 KB |
Output is correct |
73 |
Correct |
98 ms |
29168 KB |
Output is correct |
74 |
Correct |
61 ms |
26052 KB |
Output is correct |
75 |
Correct |
106 ms |
43016 KB |
Output is correct |
76 |
Correct |
120 ms |
34328 KB |
Output is correct |
77 |
Correct |
90 ms |
42508 KB |
Output is correct |
78 |
Correct |
94 ms |
41688 KB |
Output is correct |
79 |
Correct |
99 ms |
43964 KB |
Output is correct |
80 |
Correct |
74 ms |
42976 KB |
Output is correct |
81 |
Correct |
134 ms |
31968 KB |
Output is correct |
82 |
Correct |
135 ms |
32040 KB |
Output is correct |
83 |
Correct |
111 ms |
44004 KB |
Output is correct |
84 |
Correct |
88 ms |
39560 KB |
Output is correct |
85 |
Correct |
134 ms |
32084 KB |
Output is correct |
86 |
Correct |
112 ms |
44060 KB |
Output is correct |
87 |
Correct |
112 ms |
44108 KB |
Output is correct |
88 |
Correct |
91 ms |
33980 KB |
Output is correct |
89 |
Correct |
127 ms |
32560 KB |
Output is correct |
90 |
Correct |
144 ms |
32564 KB |
Output is correct |
91 |
Correct |
145 ms |
32144 KB |
Output is correct |
92 |
Correct |
157 ms |
32180 KB |
Output is correct |
93 |
Correct |
124 ms |
30668 KB |
Output is correct |
94 |
Correct |
107 ms |
30972 KB |
Output is correct |
95 |
Correct |
81 ms |
35612 KB |
Output is correct |
96 |
Correct |
73 ms |
42876 KB |
Output is correct |
97 |
Correct |
83 ms |
23560 KB |
Output is correct |
98 |
Correct |
105 ms |
29108 KB |
Output is correct |
99 |
Correct |
108 ms |
32452 KB |
Output is correct |
100 |
Correct |
36 ms |
14680 KB |
Output is correct |
101 |
Correct |
149 ms |
32272 KB |
Output is correct |
102 |
Correct |
113 ms |
29792 KB |
Output is correct |
103 |
Correct |
129 ms |
31756 KB |
Output is correct |
104 |
Correct |
145 ms |
32860 KB |
Output is correct |