Submission #995712

#TimeUsernameProblemLanguageResultExecution timeMemory
995712MilosMilutinovicPipes (BOI13_pipes)C++14
74.07 / 100
130 ms23636 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<vector<array<int, 2>>> g(n); for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; --x; --y; g[x].push_back({y, i}); g[y].push_back({x, i}); } if (m >= n) { cout << 0 << '\n'; return 0; } if (n == 1) { cout << 2 * a[0] << '\n'; return 0; } if (m < n) { vector<long long> res(m); function<void(int, int)> Dfs = [&](int v, int pv) { for (auto& e : g[v]) { int u = e[0]; if (u == pv) { continue; } Dfs(u, v); if (a[u] != 0) { res[e[1]] = 2 * a[u]; a[v] -= a[u]; } } }; Dfs(0, 0); if (a[0] != 0) { cout << 0 << '\n'; return 0; } for (int i = 0; i < m; i++) { cout << res[i] << '\n'; } return 0; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...