Submission #111612

#TimeUsernameProblemLanguageResultExecution timeMemory
111612wilwxkPipes (BOI13_pipes)C++11
30 / 100
1083 ms132096 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN=1e5+5; vector<int> g[MAXN], lista[MAXN]; int v[MAXN], tenho[MAXN], resp[MAXN]; int n, m; void dfs(int cur, int p) { tenho[cur]=0; for(int i=0; i<g[cur].size(); i++) { int viz=g[cur][i]; int ind=lista[cur][i]; if(viz==p) continue; dfs(viz, cur); resp[ind]=v[viz]-tenho[viz]; tenho[cur]+=resp[ind]; } } int main() { scanf("%d %d", &n, &m); for(int i=1; i<=n; i++) scanf("%d", &v[i]); for(int i=1; i<=m; i++) { int a, b; scanf("%d %d", &a, &b); g[a].push_back(b); g[b].push_back(a); lista[a].push_back(i); lista[b].push_back(i); } dfs(1, 1); if(tenho[1]!=v[1]) { printf("0\n"); } else { for(int i=1; i<=m; i++) { printf("%d\n", resp[i]*2); } } }

Compilation message (stderr)

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:11:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<g[cur].size(); i++) {
               ~^~~~~~~~~~~~~~
pipes.cpp: In function 'int main()':
pipes.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:22:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=n; i++) scanf("%d", &v[i]);
                          ~~~~~^~~~~~~~~~~~~
pipes.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...