Submission #1125715

#TimeUsernameProblemLanguageResultExecution timeMemory
1125715MuhammetPipes (BOI13_pipes)C++20
30 / 100
1102 ms196608 KiB
#include <bits/stdc++.h> using namespace std; int n, m; map <pair<int,int>,int> ans; vector <int> a, u1, u2; vector <vector <int>> v; void dfs(int x, int y){ for(auto i : v[x]){ if(i == y) continue; dfs(i, x); ans[{min(i,x),max(i,x)}] = (a[i]*2); a[x] -= a[i]; } return; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; a.resize(n+1); for(int i = 1; i <= n; i++){ cin >> a[i]; } v.resize(n+1); u1.resize(m+1), u2.resize(m+1); for(int i = 1; i <= m; i++){ cin >> u1[i] >> u2[i]; v[u1[i]].push_back(u2[i]); v[u2[i]].push_back(u1[i]); } dfs(1, 0); for(int i = 1; i <= m; i++){ cout << ans[{min(u1[i],u2[i]), max(u1[i],u2[i])}] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...