This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
if (n != m+1) {
cout << 0 << '\n';
return 0;
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |