#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(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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9812 KB |
Output is correct |
5 |
Correct |
5 ms |
9812 KB |
Output is correct |
6 |
Runtime error |
308 ms |
524288 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9732 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
99 ms |
31992 KB |
Output is correct |
4 |
Incorrect |
107 ms |
31056 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
133 ms |
27676 KB |
Output is correct |
3 |
Correct |
134 ms |
27724 KB |
Output is correct |
4 |
Correct |
111 ms |
31896 KB |
Output is correct |
5 |
Correct |
100 ms |
30372 KB |
Output is correct |
6 |
Correct |
142 ms |
27656 KB |
Output is correct |
7 |
Correct |
115 ms |
39732 KB |
Output is correct |
8 |
Correct |
127 ms |
39768 KB |
Output is correct |
9 |
Correct |
72 ms |
39420 KB |
Output is correct |
10 |
Correct |
106 ms |
30260 KB |
Output is correct |
11 |
Correct |
118 ms |
29216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Runtime error |
357 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
4 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9812 KB |
Output is correct |
5 |
Correct |
5 ms |
9812 KB |
Output is correct |
6 |
Runtime error |
308 ms |
524288 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |