#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];
}
void dfs(int k,int flag,vector<int> &can,vector<int> adj[]){
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+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);
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(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 |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Runtime error |
3 ms |
4188 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
114 ms |
36188 KB |
Output is correct |
4 |
Incorrect |
120 ms |
33836 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Runtime error |
169 ms |
62548 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1884 KB |
Output is correct |
2 |
Runtime error |
197 ms |
64540 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1884 KB |
Output is correct |
4 |
Runtime error |
3 ms |
4188 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |