Submission #654456

#TimeUsernameProblemLanguageResultExecution timeMemory
654456ktkeremStranded Far From Home (BOI22_island)C++17
40 / 100
1099 ms48208 KiB
#include<bits/stdc++.h> typedef long long ll; typedef std::pair<ll , ll> llll; #define fi first #define sec second #define all(x) x.begin() , x.end() #define pb push_back const ll ous = 2e5+7; std::vector<llll> ar ;std::vector<ll> adj[ous] , nds(ous , 0) , par(ous) , sz(ous) , ans(ous , 1) , rar(ous) , kr(ous) , ant(ous); ll n , m , o; ll fin(ll x){ if(par[x] == x){ return x; } return par[x] = fin(par[x]); } void mrg(ll x , ll y){ x = fin(x);y = fin(y); if(sz[y] > sz[x]){ std::swap(x , y); } if(x != y){ par[y] = x; sz[x] += sz[y]; } } void dfs(ll crt){ o += rar[crt]; nds[crt] = 1; for(auto j:adj[crt]){ if(fin(crt) != fin(j) && nds[j] == 0){ mrg(crt , j); dfs(j); } } } void solve(){ ll n , m;std::cin >> n >> m; ar.resize(n); for(ll i = 0;n>i;i++){ std::cin >> ar[i].fi; ar[i].sec = i + 1; rar[i+1] = ar[i].fi; } for(ll i = 0;m>i;i++){ ll x , y;std::cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } std::sort(all(ar) , std::greater<llll>()); ll ik = 1; for(;n > ik;ik++){ if(ar[ik].fi != ar[ik-1].fi){ break; } } while(n > ik){ for(ll i = 0;n>=i;i++){ par[i] = i; sz[i] = 1; nds[i] = 0; kr[i] = 0; ant[i] = 0; } for(ll i = 0;ik>i;i++){ nds[ar[i].sec] = 1; } for(ll i = ik;n>i;i++){ ans[ar[i].sec] = 0; } for(ll i = 1;n>=i;i++){ if(nds[i] == 0){ dfs(i); kr[fin(i)] += o; o = 0; } } for(ll i = 0;ik>i;i++){ for(auto j:adj[ar[i].sec]){ ll ff = fin(j); if(kr[ff] >= ar[i].fi){ ant[ff] |= ans[ar[i].sec]; } } } for(ll i = 1;n>=i;i++){ ans[i] |= ant[fin(i)]; //std::cout << ans[i] << " "; } // std::cout <<"\n\n\n"; ik++; for(;n > ik;ik++){ if(ar[ik-1].fi != ar[ik].fi){ break; } } } for(ll i = 1;n>=i;i++){ std::cout << ans[i]; } std::cout <<"\n"; } signed main(){ std::ios_base::sync_with_stdio(false); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...