#include <bits/stdc++.h>
using namespace std;
#define int long long
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
const int N=200005;
const int INF=1e18;
const int mod=1e9+9;
vector<int> pa(N);
int Find(int k){
return (pa[k]==k?k:pa[k]=Find(pa[k]));
}
void onion(int a,int b,vector<int> &pw){
a=Find(a),b=Find(b);
if(a==b)return;
pa[a]=b;
pw[b]+=pw[a];
}
int cnt1=0;
void dfs(int k,int flag,vector<int> &can,vector<int> adj[]){
cnt1++;
can[k]&=flag;
for(int j:adj[k]){
dfs(j,can[k],can,adj);
}
}
int32_t main() {
LCBorz;
iota(all(pa),0);
int n,m;cin>>n>>m;
vector<int> v(N),pw(N),t(n),use(N);
vector<int> adj[N],can(N,1),g[N],ing(N);
for(int i=1;i<=n;i++){
cin>>v[i];pw[i]=v[i];
}
for(int i=0;i<m;i++){
int a,b;cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
iota(all(t),1);
sort(all(t),[&](int a,int b){return v[a]<v[b];});
for(int i:t){
for(int j:adj[i]){
if(!use[j])continue;
int t=Find(j);
if(pw[t]<v[i])can[j]=0;
if(!ing[t]){
ing[t]=1;
g[i].push_back(t);
}
}
for(int j:adj[i]){
if(use[j])ing[Find(j)]=0;
}
for(int j:adj[i]){
if(use[j])onion(j,i,pw);
}
use[i]=1;
}
dfs(v[n-1],1,can,g);
for(int i=1;i<=n;i++){
cout<<can[i];
}
cout<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19036 KB |
Output is correct |
3 |
Correct |
9 ms |
19036 KB |
Output is correct |
4 |
Runtime error |
24 ms |
38748 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19032 KB |
Output is correct |
3 |
Correct |
114 ms |
36240 KB |
Output is correct |
4 |
Incorrect |
110 ms |
33364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19036 KB |
Output is correct |
2 |
Runtime error |
173 ms |
62856 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19032 KB |
Output is correct |
2 |
Runtime error |
194 ms |
64772 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19032 KB |
Output is correct |
2 |
Correct |
9 ms |
19036 KB |
Output is correct |
3 |
Correct |
9 ms |
19036 KB |
Output is correct |
4 |
Runtime error |
24 ms |
38748 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |