Submission #755439

#TimeUsernameProblemLanguageResultExecution timeMemory
755439drdilyorPipes (BOI13_pipes)C++17
30 / 100
80 ms10760 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; const ll infl = 1e18; signed main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; assert(n == m+1); vector<int> arr(n); for (int& i : arr) cin >> i; vector<vector<pair<int,int>>> adj(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--;v--; adj[u].push_back({v, i}); adj[v].push_back({u, i}); } vector<int> ans(m); auto dfs = [&](auto& dfs, int i, int p =-1,int pei=-1) ->void { int c = 0; for (auto [e, ei]: adj[i]) { if (e == p) continue; c++; dfs(dfs, e, i, ei); } if (p!=-1) { ans[pei] = arr[i]; arr[p] -= arr[i]; } }; dfs(dfs, 0); for (int i : ans) cout << i*2<< ' '; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...