Submission #755489

#TimeUsernameProblemLanguageResultExecution timeMemory
755489The_SamuraiPipes (BOI13_pipes)C++17
30 / 100
59 ms8296 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; if (n != m + 1) { return 0; } vector<vector<pair<int, int>>> g(n + 1); vector<int> cnt(n + 1), ans(m), a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; g[u].emplace_back(v, i); g[v].emplace_back(u, i); } queue<int> q; vector<bool> vis(n + 1); for (int i = 1; i <= n; i++) { cnt[i] = g[i].size(); if (cnt[i] == 1) { q.push(i); } } while (!q.empty()) { int u = q.front(); q.pop(); vis[u] = true; for (auto [v, i]: g[u]) { if (vis[v]) continue; cnt[v]--; if (cnt[v] == 1) q.push(v); ans[i] = a[u] * 2; a[v] -= a[u]; } } for (int x: ans) cout << x << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...