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 nx=1e5+5;
int n, m, h[nx], u, v, sz, res[nx];
vector<pair<int, int>> d[nx];
void dfs(int u, int p, int idx)
{
for (auto [v, id]:d[u]) if (v!=p) dfs(v, u, id);
if (idx==-1) return;
res[idx]=2*h[u];
h[p]-=h[u];
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=n; i++) cin>>h[i];
for (int i=1; i<=m; i++) cin>>u>>v, d[u].push_back({v, i}), d[v].push_back({u, i});
if (m>=n)
{
cout<<0;
return 0;
}
dfs(1, 1, -1);
for (int i=1; i<n; i++) cout<<res[i]<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |