Submission #583944

#TimeUsernameProblemLanguageResultExecution timeMemory
583944cheissmartStranded Far From Home (BOI22_island)C++14
100 / 100
478 ms50820 KiB
#include <bits/stdc++.h> #define IO_OP ios::sync_with_stdio(0), cin.tie(0) #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(v) int((v).size()) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 2e5 + 7; int s[N], where[N], ans[N], pos[N]; ll sum[N]; vi who[N], alive[N]; vi G[N]; signed main() { IO_OP; int n, m; cin >> n >> m; for(int i = 1; i <= n; i++) cin >> s[i]; vi p(n); iota(ALL(p), 1); sort(ALL(p), [&] (int a, int b) { return s[a] < s[b]; }); for(int i = 0; i < n; i++) pos[p[i]] = i; for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; G[u].PB(v); G[v].PB(u); } auto unite = [&] (int x, int y) { if(SZ(who[x]) > SZ(who[y])) swap(x, y); for(int u:who[x]) { who[y].PB(u); where[u] = y; } sum[y] += sum[x]; if(SZ(alive[x]) > SZ(alive[y])) swap(alive[x], alive[y]); for(int u:alive[x]) alive[y].PB(u); }; for(int u:p) { ans[u] = 1; where[u] = u, who[u].PB(u), alive[u].PB(u), sum[u] = s[u]; vi cc; for(int v:G[u]) if(pos[v] < pos[u]) cc.PB(where[v]); sort(ALL(cc)); cc.resize(unique(ALL(cc)) - cc.begin()); for(int c:cc) if(sum[c] < s[u]) { for(int v:alive[c]) ans[v] = 0; alive[c].clear(); } for(int c:cc) unite(where[u], c); } for(int i = 1; i <= n; i++) cout << ans[i]; cout << '\n'; }
#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...