Submission #885095

#TimeUsernameProblemLanguageResultExecution timeMemory
88509512345678Pipes (BOI13_pipes)C++17
74.07 / 100
106 ms23644 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...