Submission #1121747

#TimeUsernameProblemLanguageResultExecution timeMemory
1121747vjudge1Stranded Far From Home (BOI22_island)C++17
20 / 100
973 ms524288 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]; int a[N]; bool ans[N]; int ls[N]; int us[N]; void dfs(int v,int p){ ls[v]=a[v]; 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]); } for(int to : g[v]){ if(to == p) continue; dfs2(to , v); } } void solve() { int n,m; cin >> n >> m; vector<pll> v; for(int i=1 ; i <= n ; i++){ cin >> a[i]; v.pb({a[i] , 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(all(v)); reverse(all(v)); for(int i=0 ; i < n ; i++){ int j=v[i].S; us[j]=j; set<pll> st; int cnt=0; ans[j]=0; st.in({0 , j}); while(!st.empty()){ auto 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]; for(int to : g[v]){ if(us[to] != j){ us[to]=j; st.in({a[to] , 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...