#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |