Submission #1125632

#TimeUsernameProblemLanguageResultExecution timeMemory
1125632KerimPipes (BOI13_pipes)C++20
0 / 100
3 ms2784 KiB
#include "bits/stdc++.h" #define ff first #define ss second #define ll long long using namespace std; const int N = 1e5+5; vector<pair<int,int> > adj[N]; pair<int, int> par[N]; vector<int> order; ll a[N], ans[N]; void dfs(int nd, int pr){ for (auto [to, ind]: adj[nd]){ if (to == pr) continue; par[to] = {nd, ind}; dfs(to, nd); } order.push_back(nd); } int main(){ freopen("file.in", "r", stdin); int n, m; scanf("%d%d", &n, &m); assert(m == n-1); for (int i = 1; i <= n; i++) scanf("%lld", a+i); for (int i = 1; i <= m; i++){ int u, v; scanf("%d%d", &u, &v); adj[u].push_back({v, i}); adj[v].push_back({u, i}); } dfs(1, -1); for (auto x: order){ ans[par[x].ss] = a[x] * 2; a[par[x].ff] -= a[x]; x = par[x].ff; } if (!a[1]){ for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]); } else puts("0"); return 0; }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen("file.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
pipes.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%lld", a+i);
      |         ~~~~~^~~~~~~~~~~~~
pipes.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...