Submission #443981

#TimeUsernameProblemLanguageResultExecution timeMemory
443981aryan12Pipes (BOI13_pipes)C++17
65 / 100
231 ms32472 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e5 + 5; int change[N], result[N]; vector<pair<int, int> > g[N]; int edgeChange[N]; int n, m; void dfs(int node, int par, int edgeNum) { for(int i = 0; i < g[node].size(); i++) { if(g[node][i].first != par) { dfs(g[node][i].first, node, g[node][i].second); } } int netWithParent = change[node] - result[node]; if(par != -1) { result[node] += netWithParent; edgeChange[edgeNum] = netWithParent; result[par] += netWithParent; } } void Tree() { dfs(1, -1, -1); if(result[1] != change[1]) { cout << "0\n"; return; } for(int i = 1; i <= m; i++) { cout << edgeChange[i] * 2 << "\n"; } } void Solve() { cin >> n >> m; for(int i = 1; i <= n; i++) { cin >> change[i]; } for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].push_back(make_pair(v, i)); g[v].push_back(make_pair(u, i)); } if(m == n - 1) { Tree(); return; } if(m > n) { cout << "0\n"; return; } } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--) { Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }

Compilation message (stderr)

pipes.cpp: In function 'void dfs(long long int, long long int, long long int)':
pipes.cpp:14:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0; i < g[node].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...