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;
const int MAX_N = 1e5 + 5;
vector<pair<int, int>> G[MAX_N];
int c[MAX_N], x[MAX_N];
void DFS(int u, int p) {
for (auto [v, i] : G[u]) {
if (v != p) {
DFS(v, u);
x[i] = c[v];
c[u] -= x[i];
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M;
cin >> N >> M;
for (int i = 0; i < N; i++) {
cin >> c[i];
}
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
u--, v--;
G[u].push_back({v, i});
G[v].push_back({u, i});
}
DFS(0, -1);
for (int i = 0; i < M; i++) {
cout << x[i] * 2 << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |