#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,-1);
int Find(int k){
return (pa[k]<0?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;
if(pa[a]<pa[b])swap(a,b);
pa[b]+=pa[a];
pa[a]=b;
pw[b]+=pw[a];
}
void dfs(int k,int pa,int flag,vector<int> &can,vector<int> adj[]){
can[k]&=flag;
for(int j:adj[k]){
if(j==pa)continue;
dfs(j,k,can[k],can,adj);
}
}
int32_t main() {
LCBorz;
int n,m;cin>>n>>m;
vector<int> v(n+1),pw(n+1),t(n),use(n+1);
vector<int> adj[n+1],can(n+1,1),g[n+1],ing(n+1);
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);
//cout<<i<<' '<<t<<' '<<pw[t]<<' '<<v[i]<<endl;
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])onion(i,j,pw);
}
use[i]=1;
}
dfs(1,1,1,can,g);
for(int i=1;i<=n;i++){
cout<<can[i];
}
cout<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
100 ms |
34128 KB |
Output is correct |
4 |
Incorrect |
97 ms |
31824 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Incorrect |
141 ms |
33404 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Incorrect |
135 ms |
34388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |