# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
699685 | finn__ | Pipes (BOI13_pipes) | C++17 | 61 ms | 12336 KiB |
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;
#define N 100000
#define M 500000
vector<pair<unsigned, unsigned>> g[N];
int64_t y[N], ans[M];
int64_t solve_for_tree(unsigned u, unsigned p1 = -1, unsigned p2 = -1)
{
int64_t val = 0;
for (auto const &[v, i] : g[u])
if (v != p1 && v != p2)
{
int64_t z = solve_for_tree(v, u);
ans[i] = y[v] - z;
val += ans[i];
}
return val;
}
int main()
{
size_t n, m;
scanf("%zu %zu", &n, &m);
if (m > n)
{
printf("0\n");
return 0;
}
for (size_t i = 0; i < n; i++)
scanf("%" PRId64, y + i);
for (size_t i = 0; i < m; i++)
{
unsigned u, v;
scanf("%u %u", &u, &v);
g[u - 1].emplace_back(v - 1, i);
g[v - 1].emplace_back(u - 1, i);
}
if (m + 1 == n)
solve_for_tree(0);
else
{
}
for (size_t i = 0; i < m; i++)
printf("%" PRId64 "\n", 2 * ans[i]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |