Submission #722976

#TimeUsernameProblemLanguageResultExecution timeMemory
722976dxz05Stranded Far From Home (BOI22_island)C++17
10 / 100
1082 ms13116 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() #define MP make_pair const int N = 200500; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int n; vector<int> g[N]; int s[N]; bool can[N]; bool check(int v){ queue<int> q; q.push(v); vector<bool> used(n, false); used[v] = true; ll sum = 0; set<pair<int, int>> blocked; while (!q.empty()){ v = q.front(); q.pop(); sum += s[v]; while (!blocked.empty() && blocked.begin()->first <= sum){ int x = blocked.begin()->second; q.push(x); used[x] = true; if (can[x]) return true; blocked.erase(blocked.begin()); } for (int u : g[v]){ if (used[u]) continue; if (s[u] <= sum){ q.push(u); used[u] = true; if (can[u]) return true; } else { blocked.emplace(s[u], u); } } } return count(all(used), true) == n; } void solve(){ int m; cin >> n >> m; for (int i = 0; i < n; i++){ cin >> s[i]; } while (m--){ int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } vector<int> perm(n); iota(all(perm), 0); shuffle(all(perm), rng); for (int i : perm) can[i] = check(i); for (int i = 0; i < n; i++){ cout << can[i]; } cout << endl; } int main() { ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif 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...