Submission #17658

#TimeUsernameProblemLanguageResultExecution timeMemory
17658NamnamseoSenior Postmen (BOI14_postmen)C++14
100 / 100
399 ms20012 KiB
#include <cstdio> #include <vector> int n,m; int start[ 500010]; int endp [1000010]; int next [1000010]; bool dead[1000010]; int counter; void addEdge(int from,int to) { next [counter] = start[from]; start[from ] = counter; endp [counter] = to; ++counter; } int stack[500010]; int hi [500010]; int top=-1; void push(int x) { stack[++top]=x; } int pop ( ) { return stack[top--]; } bool visited[500010]; int main() { counter=1; scanf("%d%d",&n,&m); int i,a,b; for(i=0;i<m;i++){ scanf("%d%d",&a,&b); addEdge(a,b); addEdge(b,a); } push(1); int cur; int t=0; while(top>=0) { cur=stack[top]; while(dead[start[cur]] && start[cur]) { start[cur]=next[start[cur]]; } if(start[cur]==0) { hi[t++]=cur; --top; continue; } else { push(endp[start[cur]]); dead[start[cur]]=true; if(start[cur]%2){ dead[start[cur]+1]=true; } else dead[start[cur]-1]=true; } } top=-1; int temp; for(i=0;i<t;++i) { cur = hi[i]; //printf("%d ",cur); if(visited[cur]) { while((temp=pop())!=cur) { printf("%d ",temp); visited[temp]=false; } printf("%d\n",cur); push(cur); } else { visited[cur]=true; push(cur); } } }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
postmen.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...