//Author RufatM
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ff first
#define ss second
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
const int MOD=998244353;
const int INF=1e9;
const ll LINF=1e18;
const int MAXN=200005;
ll n,m,s[MAXN],p[MAXN],sz[MAXN];
vi g[MAXN],o[MAXN];
bool vis[MAXN];
char ans[MAXN];
int find(int i){
if(p[i]==i){
return i;
}
return p[i] = find(p[i]);
}
void dfs(int u,bool ok){
if(ok){
ans[u-1] = '1';
}
else{
ans[u-1] = '0';
}
for(int i=0;i<o[u].size();i++){
int ch = o[u][i];
bool nxt = false;
if(ok and sz[ch]>=s[u]){
nxt = true;
}
dfs(ch,nxt);
}
}
signed main(){
fastio;
int t=1;
//cin >> t;
while(t--){
cin >> n >> m;
vector<pii> a(n);
for(int i=1;i<=n;i++){
cin >> s[i];
a[i-1] = {s[i],i};
p[i] = i;
sz[i] = s[i];
}
for(int i=0;i<m;i++){
int u,v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
sort(all(a));
for(int i=0;i<n;i++){
int u = a[i].ss;
vis[u] = true;
for(int j=0;j<g[u].size();j++){
if(vis[g[u][j]]){
int root = find(g[u][j]);
if(root != u){
p[root] = u;
o[u].pb(root);
sz[u] += sz[root];
}
}
}
}
dfs(a[n-1].ss,true);
ans[n] = '\0';
cout << ans << endl;
}
}
| # | 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... |