#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,val[200010],tag[200010],subsum[200010],dsu[200010],ans[200010];
vector<ll> e[200010],te[200010];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
int f(int now){
if(dsu[now]!=now) dsu[now]=f(dsu[now]);
return dsu[now];
}
void onion(int a,int b){
a=f(a);
b=f(b);
if(a!=b) dsu[b]=a,subsum[a]+=subsum[b];
return;
}
void dfs(int now,int x){
ans[now]=x;
if(tag[now]==1)ans[now]=0;
for(auto ne:te[now]){
dfs(ne,ans[now]);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
int last=1;
for(int i=1;i<=n;i++){
cin>>val[i];
pq.push(make_pair(val[i],i));
dsu[i]=i;
subsum[i]=val[i];
}
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
if(val[a]>val[b])e[a].push_back(b);
else e[b].push_back(a);
}
while(!pq.empty()){
auto x=pq.top();
pq.pop();
last=x.second;
for(auto ne:e[x.second]){
ne=f(ne);
if(ne==x.second)continue;
te[x.second].push_back(ne);
if(subsum[ne]<x.first)tag[ne]=1;
onion(x.second,ne);
}
}
dfs(last,1);
for(int i=1;i<=n;i++)cout<<ans[i];
cout<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9676 KB |
Output is correct |
3 |
Correct |
5 ms |
9728 KB |
Output is correct |
4 |
Correct |
5 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Runtime error |
252 ms |
524288 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
4 ms |
9684 KB |
Output is correct |
3 |
Correct |
110 ms |
36400 KB |
Output is correct |
4 |
Incorrect |
109 ms |
34016 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Correct |
155 ms |
27472 KB |
Output is correct |
3 |
Correct |
158 ms |
32040 KB |
Output is correct |
4 |
Correct |
109 ms |
36284 KB |
Output is correct |
5 |
Correct |
105 ms |
33128 KB |
Output is correct |
6 |
Correct |
155 ms |
31976 KB |
Output is correct |
7 |
Correct |
120 ms |
44000 KB |
Output is correct |
8 |
Correct |
115 ms |
44068 KB |
Output is correct |
9 |
Correct |
86 ms |
43056 KB |
Output is correct |
10 |
Correct |
97 ms |
34036 KB |
Output is correct |
11 |
Correct |
126 ms |
32272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9684 KB |
Output is correct |
2 |
Execution timed out |
1060 ms |
524288 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9676 KB |
Output is correct |
3 |
Correct |
5 ms |
9728 KB |
Output is correct |
4 |
Correct |
5 ms |
9940 KB |
Output is correct |
5 |
Correct |
5 ms |
9940 KB |
Output is correct |
6 |
Runtime error |
252 ms |
524288 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |