제출 #755496

#제출 시각아이디문제언어결과실행 시간메모리
755496drdilyorPipes (BOI13_pipes)C++17
72.78 / 100
59 ms9164 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; const ll infl = 1e18; signed main() { cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; if (n != m+1) { if (n == m && n % 2 == 1) exit(1); cout << 0 << '\n'; return 0; } vector<int> arr(n); for (int& i : arr) cin >> i; vector<vector<pair<int,int>>> adj(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--;v--; adj[u].push_back({v, i}); adj[v].push_back({u, i}); } vector<int> ans(m); auto dfs = [&](auto& dfs, int i, int p =-1,int pei=-1) ->void { int c = 0; for (auto [e, ei]: adj[i]) { if (e == p) continue; c++; dfs(dfs, e, i, ei); } if (p!=-1) { ans[pei] = arr[i]; arr[p] -= arr[i]; } }; dfs(dfs, 0); for (int i : ans) cout << i*2<< ' '; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...