Submission #885117

#TimeUsernameProblemLanguageResultExecution timeMemory
88511712345678Pipes (BOI13_pipes)C++17
74.07 / 100
148 ms39796 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=5e5+5; int n, m, h[nx], u, v, sz, res[nx], vs[nx], lvl[nx], f; vector<pair<int, int>> d[nx]; void dfs(int u, int p, int idx) { vs[u]=1; lvl[u]=lvl[p]+1; for (auto [v, id]:d[u]) { if (v==p) continue; if (!vs[v]) dfs(v, u, id); else if ((lvl[u]-lvl[v]+1)%2==0) f=1; } 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}); dfs(1, 1, -1); if (m>n||f) { cout<<0; return 0; } for (int i=1; i<n; i++) cout<<res[i]<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...