Submission #26391

#TimeUsernameProblemLanguageResultExecution timeMemory
26391samir_droubiPipes (BOI13_pipes)C++14
74.07 / 100
676 ms56308 KiB
#include <bits/stdc++.h> using namespace std; int n,m; const int mxn=(1e5)+5; long long c[mxn]; queue<int>q; set<pair<int,int> >gr[mxn]; int ans[mxn*5]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) scanf("%d",&c[i]); for(int i=1;i<=m;++i) { int x,y; scanf("%d%d",&x,&y); gr[x].insert({y,i}); gr[y].insert({x,i}); } if(m>=n) { puts("0"); return 0; } for(int i=1;i<=n;++i) if(gr[i].size()==1)q.push(i); while(!q.empty()) { int v=q.front(); q.pop(); if(gr[v].empty())continue; int u=gr[v].begin()->first; int in=gr[v].begin()->second; gr[u].erase({v,in}); if(gr[u].size()==1)q.push(u); ans[in]=2*c[v]; c[u]-=c[v]; } for(int i=1;i<=m;++i)printf("%d\n",ans[i]); return 0; }

Compilation message (stderr)

pipes.cpp: In function 'int main()':
pipes.cpp:13:19: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   scanf("%d",&c[i]);
                   ^
pipes.cpp:11:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
pipes.cpp:13:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&c[i]);
                    ^
pipes.cpp:17:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&x,&y);
                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...