#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 200005
ll n,m;
pll a[maxn];
vector<ll> g[maxn];
ll dsu[maxn],sizi[maxn],sum[maxn];
bool los[maxn];
bool vis[maxn];
ll root(ll x){
while(x!=dsu[x]) x = dsu[x];
return x;
}
void upd(ll x,ll y){
x = root(x); y = root(y);
if(x==y) return;
if(sizi[x]>sizi[y]) swap(x,y);
dsu[x] = y;
sizi[y]+=sizi[x];
sum[y]+=sum[x];
}
void tc(){
cin >> n >> m;
for(ll i = 1;i<=n;i++) cin >> a[i].fi;
for(ll i = 1;i<=n;i++) a[i].sc = i;
for(ll i = 1;i<=n;i++) sum[i] = a[i].fi;
for(ll i = 1;i<=m;i++){
ll x,y; cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
iota(dsu+1,dsu+1+n,1);
fill(sizi+1,sizi+1+n,1);
sort(a+1,a+1+n);
for(ll j = 1;j<=n;j++){
ll i = a[j].sc;
ll x = a[j].fi;
vis[i] = 1;
for(ll j : g[i]){
if(!vis[j]) continue;
j = root(j);
if(sum[j]<x) los[j] = 1;
}
for(ll j : g[i]){
if(!vis[j]) continue;
upd(i,j);
}
}
for(ll i = 1;i<=n;i++){
ll x = i;
bool ok = 1;
while(x!=dsu[x]){
if(los[i]) ok = 0;
x = dsu[x];
}
if(sizi[x]!=n) ok = 0;
cout<<ok;
}
cout<<endl;
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5032 KB |
Output is correct |
2 |
Correct |
3 ms |
5032 KB |
Output is correct |
3 |
Incorrect |
168 ms |
25108 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
192 ms |
24012 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
204 ms |
24996 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |