Submission #722916

#TimeUsernameProblemLanguageResultExecution timeMemory
722916kas_sStranded Far From Home (BOI22_island)C++17
0 / 100
414 ms12784 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int N; vector<vector<int>> adj; vector<int> cnt; vector<bool> vis; int curr = 0; void dfs(int pos) { vis[pos] = true; curr += cnt[pos]; for (auto &v: adj[pos]) { if (vis[v] || cnt[v] > curr) continue; dfs(v); } } bool comp(int a, int b) { return cnt[a] < cnt[b]; } int main() { ios::sync_with_stdio(0); cin.tie(0); int M; cin >> N >> M; cnt.resize(N + 1); for (int i = 1; i <= N; i++) cin >> cnt[i]; adj.resize(N + 1); for (int i = 0, u, v; i < M; i++) { cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= N; i++) { sort(adj[i].begin(), adj[i].end(), comp); } string res; vis.resize(N + 1); for (int i = 1; i <= N; i++) { fill(vis.begin(), vis.end(), false); curr = 0; dfs(i); bool ok = true; for (int i = 1; i <= N; i++) { if (!vis[i]) { ok = false; break; } } res.push_back((ok ? '1' : '0')); } cout << res; 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...