Submission #1121720

#TimeUsernameProblemLanguageResultExecution timeMemory
1121720vjudge1Stranded Far From Home (BOI22_island)C++17
0 / 100
1092 ms494424 KiB
#include <bits/stdc++.h> #define ll long long #define all(x) x.begin(), x.end() #define in insert #define F first #define S second #define ppf pop_front #define pb push_back #define ppb pop_back #define pf push_front #define pii pair <int, int> #define pll pair <ll, ll> #define boost() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define sz(x) (int)x.size() #define int ll using namespace std; const int N = 2e5+123; const ll mod = 1e9+7; vector<int> g[N]; pll a[N]; bool ans[N]; int ls[N]; int us[N]; void dfs(int v,int p){ ls[v]=a[v].F; for(int to : g[v]){ if(to == p) continue; dfs(to , v); ls[v]+=ls[to]; } } void dfs2(int v , int p){ if(!ans[p]) ans[v]=0; else{ ans[v]=(ls[v] >= a[p].F); } for(int to : g[v]){ if(to == p) continue; dfs2(to , v); } } void solve() { int n,m; cin >> n >> m; for(int i=1 ; i <= n ; i++){ cin >> a[i].F; a[i].S=i; } for(int i=1 ; i <= m ; i++){ int v,u; cin >> v >> u; g[u].pb(v); g[v].pb(u); } // for(int i=1 ; i <= n ; i++){ // cout << a[i].F << " " << a[i].S << endl; // } if(n <= 2000 && m <= 2000){ sort(a+1 , a+1+n); for(int i=n ; i >= 1 ; i--){ int j=a[i].S; us[j]=j; set<pll> st; int cnt=0; st.in({0 , j}); while(!st.empty()){ pll o=*st.begin(); st.erase(o); int x=o.F; int v=o.S; if(cnt < x){ ans[j]=0; break; } if(ans[v] == 1){ ans[j]=1; break; } cnt+=a[v].F; for(int to : g[v]){ if(us[to] != j){ us[to]=j; st.in({a[to].F , to}); } } if(st.empty()){ ans[j]=1; } } } for(int i=1 ; i <= n ; i++){ cout << ans[i]; } return; } ans[0]=1; dfs(1 , 0); dfs2(1 , 0); for(int i=1 ; i <= n ; i++){ cout << ans[i]; } } /* 4 4 2 2 4 3 1 2 1 3 2 3 3 4 */ signed main() { boost(); int tt=1; //cin >> tt; while (tt--) { 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...