Submission #699685

#TimeUsernameProblemLanguageResultExecution timeMemory
699685finn__Pipes (BOI13_pipes)C++17
65 / 100
61 ms12336 KiB
#include <bits/stdc++.h> using namespace std; #define N 100000 #define M 500000 vector<pair<unsigned, unsigned>> g[N]; int64_t y[N], ans[M]; int64_t solve_for_tree(unsigned u, unsigned p1 = -1, unsigned p2 = -1) { int64_t val = 0; for (auto const &[v, i] : g[u]) if (v != p1 && v != p2) { int64_t z = solve_for_tree(v, u); ans[i] = y[v] - z; val += ans[i]; } return val; } int main() { size_t n, m; scanf("%zu %zu", &n, &m); if (m > n) { printf("0\n"); return 0; } for (size_t i = 0; i < n; i++) scanf("%" PRId64, y + i); for (size_t i = 0; i < m; i++) { unsigned u, v; scanf("%u %u", &u, &v); g[u - 1].emplace_back(v - 1, i); g[v - 1].emplace_back(u - 1, i); } if (m + 1 == n) solve_for_tree(0); else { } for (size_t i = 0; i < m; i++) printf("%" PRId64 "\n", 2 * ans[i]); }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%zu %zu", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%" PRId64, y + i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
pipes.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%u %u", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...