Submission #734179

#TimeUsernameProblemLanguageResultExecution timeMemory
734179PurpleCrayonStranded Far From Home (BOI22_island)C++17
0 / 100
257 ms42352 KiB
#include <bits/stdc++.h> using namespace std; #define sz(v) int(v.size()) #define ar array typedef long long ll; const int N = 2e5+10, MOD = 1e9+7; // keep removing the max node, mark component as bad if it's sum is < value of the node int n, m; int s[N], par[N]; ll sum[N]; vector<int> st[N], good[N], adj[N]; bool ans[N]; void mark_bad(int c) { c = par[c]; for (int x : good[c]) ans[x] = 0; good[c].clear(); } void union_sets(int a, int b) { a = par[a], b = par[b]; if (a == b) return; if (sz(st[a]) < sz(st[b])) swap(a, b); for (int x : st[b]) { st[a].push_back(x); } st[b].clear(); for (int x : good[b]) { good[a].push_back(x); } good[b].clear(); sum[a] += sum[b], sum[b] = 0; } void solve() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b, --a, --b; adj[a].push_back(b), adj[b].push_back(a); } for (int i = 0; i < n; i++) { par[i] = i; sum[i] = s[i]; st[i].push_back(i); good[i].push_back(i); } vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int x, int y) { return s[x] < s[y]; }); fill(ans, ans + n, 1); vector<bool> hit(n); for (int x : ord) { for (int nxt : adj[x]) { int v = par[nxt]; if (sum[v] < s[x]) { mark_bad(v); } } for (int nxt : adj[x]) if (hit[nxt]) { union_sets(x, nxt); } hit[x] = 1; } for (int i = 0; i < n; i++) cout << ans[i]; cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T--) solve(); }
#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...