#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vb vector<bool>
#define mii map<int,int>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define in(a) int a; cin>>a
#define in2(a,b) int a,b; cin>>a>>b
#define in3(a,b,c) int a,b,c; cin>>a>>b>>c
#define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d
#define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];}
#define out(a) cout<<a<<'\n'
#define out2(a,b) cout<<a<<' '<<b<<'\n'
#define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n'
#define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n'
#define pout(a) cout<<a.first<<' '<<a.second<<'\n'
#define vout(v) for(auto u : v){cout<<u<<' ';} cout<<'\n'
#define dout(a) cout<<a<<' '<<#a<<'\n'
#define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<'\n'
#define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';}
const int leg = 1e9 + 7;
const int mod = 998244353;
using namespace std;
const int mxn = 2e5 + 5;
int n,m;
vector<int>v;
vi adj[mxn];
vi et;
vi st(mxn);
vi sz(mxn);
vi par(mxn);
int timer = 0;
int euler_tour(int node, int from){
par[node] = from;
int ret = 1;
et.pb(node);
st[node] = timer;
timer++;
for(auto u : adj[node]){
if(u != from){
ret += euler_tour(u, node);
}
}
sz[node] = ret;
return ret;
}
void sub1(){
f0r(st, n){
priority_queue<pii>q;
vb vis(n);
vis[st] = 1;
for(auto u : adj[st]){
vis[u] = 1;
q.push({-v[u], u});
}
int cur = v[st];
bool ok = 1;
while(!q.empty()){
int node = q.top().second;
q.pop();
if(v[node] > cur){
ok = 0;
break;
}
else{
cur += v[node];
for(auto u : adj[node]){
if(vis[u])continue;
vis[u] = 1;
q.push({-v[u], u});
}
}
}
cout<<ok;
}
}
void sub2(){
euler_tour(0, -1);
vi values(n);
f0r(i,n){
values[i] = v[et[i]];
}
vi ps(n+1);
FOR(i, 1, n+1){
ps[i] = ps[i-1] + values[i-1];
}
//vout(values);
queue<int>q;
q.push(0);
vb vis(n);
vis[0] = 1;
vb ans(n);
while(!q.empty()){
int node = q.front();
q.pop();
//dout2(node,ps[st[node] + sz[node]] - ps[st[node]]);
//if(node != 0)dout(par[node]);
if(node == 0 || ps[st[node] + sz[node]] - ps[st[node]] >= v[par[node]]){
ans[node] = 1;
//dout(node);
for(auto u : adj[node]){
if(vis[u])continue;
vis[u] = 1;
q.push(u);
}
}
}
f0r(i,n)cout<<ans[i];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
//ifstream cin(".in");
//ofstream cout(".out");
cin>>n>>m;
v.resize(n);
f0r(i,n)cin>>v[i];
f0r(i,m){
in2(a,b);
adj[--a].pb(--b);
adj[b].pb(a);
}
/*
sub1();
cout<<'\n';
sub2();
*/
if(n <= 2000 && m <= 2000){
sub1();
}
else{
sub2();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |