Submission #1077476

#TimeUsernameProblemLanguageResultExecution timeMemory
1077476hung_nmPipes (BOI13_pipes)C++17
44.07 / 100
138 ms56912 KiB
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define pii pair<int, int> #define pipii pair<int, pair<int, int>> #define vi vector<int> #define vpi vector<pair<int, int>> #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin); #define out(name) if(fopen(name, "w")) freopen(name, "w", stdout); #define int long long const int N = 1e6 + 5; const int mod = 1e9 + 7; using namespace std; long long n, m, c[N], ans[N]; vpi ad[N]; void dfs(int u, int p) { long long res = 0; for(auto [v, pos] : ad[u]) { if(v == p) continue ; dfs(v, u); ans[pos] = 2 * c[v]; c[u] += c[v]; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); cin >> n >> m; for(int i = 1; i <= n; ++i) { cin >> c[i]; } for(int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; ad[u].pb({v, i}); ad[v].pb({u, i}); } if(m != (n-1)) { cout << 0; return 0; } dfs(1, 0); for(int i = 1; i <= m; ++i) { cout << 2*ans[i] << "\n"; } return 0; }

Compilation message (stderr)

pipes.cpp: In function 'void dfs(long long int, long long int)':
pipes.cpp:19:15: warning: unused variable 'res' [-Wunused-variable]
   19 |     long long res = 0;
      |               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...