# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1126874 | Halym2007 | Pipes (BOI13_pipes) | C++17 | 6 ms | 5224 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
#define dur exit(0)
#define dur1 return(0)
const int N = 2e5 + 5;
ll n, m, val[N], jog[N];
pii par[N];
vector <pii> v[N];
vector <int> order;
void dfs (int x, int p) {
for (pii i : v[x]) {
if (i.ff == p) continue;
dfs (i.ff, x);
par[i.ff] = {x, i.ss};
}
order.pb (x);
}
int main () {
freopen ("input.txt", "r", stdin);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
assert (n - 1 == m);
for (int i = 1; i <= n; ++i) {
cin >> val[i];
}
for (int i = 1; i <= m; ++i) {
int l, r;
cin >> l >> r;
v[l].pb ({r, i});
v[r].pb ({l, i});
}
dfs (1, -1);
// for (int i : order) {
// cout << i << " ";
// }
// return 0;
order.pop_back();
for (int i : order) {
val[par[i].ff] -= val[i];
jog[par[i].ss] = val[i];
}
if (!val[1]) {
for (int i = 1; i <= m; ++i) {
cout << jog[i] + jog[i] << "\n";
}
}
else cout << "0";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |