Submission #1024580

#TimeUsernameProblemLanguageResultExecution timeMemory
1024580overwatch9Stranded Far From Home (BOI22_island)C++17
0 / 100
162 ms760 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 2001; ll S[maxn]; vector <int> adj[maxn]; bool vis[maxn]; int x = 0; ll sz = 0; void dfs(int s) { if (vis[s]) return; vis[s] = true; x++; set <int> to_vis; for (auto i : adj[s]) { if (!vis[i]) to_vis.insert(i); } while (!to_vis.empty()) { set <int> to_rem; for (auto i : to_vis) { if (S[i] <= sz) { sz += S[i]; dfs(i); to_rem.insert(i); } } if (to_rem.empty()) break; for (auto i : to_rem) to_vis.erase(i); } } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> S[i]; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { sz = S[i]; dfs(i); if (x == n) cout << 1; else cout << 0; fill(vis, vis + n + 1, false); sz = x = 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...