Submission #714918

#TimeUsernameProblemLanguageResultExecution timeMemory
714918ibrahim001Stranded Far From Home (BOI22_island)C++14
40 / 100
1070 ms29120 KiB
#include "bits/stdc++.h" #define intt long long #define pb push_back #define endl '\n' #define F first #define S second #define pii pair<int,int> #define pll pair<intt,intt> #define ld long double using namespace std; const int sz = 2e5+5; int a[sz]; vector<int>g[sz]; set<int>s; int used[sz]; string res; intt dfs(int node, int mx){ used[node] = mx; intt res = a[node]; for ( int i : g[node] ){ if ( a[i] < mx and used[i] != mx ) res += dfs(i, mx); } return res; } void fill(int node, int mx){ res[node-1] = '0'; for ( int i : g[node] ){ if ( a[i] < mx and res[i-1] == '1' ){ fill(i, mx); } } } int i,j; int main(){ int n, m; cin >> n >> m; res.resize(n, '1'); for ( i = 1; i <= n; i++ ){ cin >> a[i]; s.insert(a[i]); } for ( i = 1; i <= m; i++ ){ int x, y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } while (!s.empty()){ int mx = *s.rbegin(); s.erase(mx); for ( i = 1; i <= n; i++ ){ if ( a[i] < mx and res[i-1] == '1' and used[i] != mx and dfs(i, mx) < 1LL*mx ){ fill(i, mx); } } } cout << res << endl; } /* 4 3 4 2 2 1 1 2 3 2 4 1 */
#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...