Submission #31557

#TimeUsernameProblemLanguageResultExecution timeMemory
31557Dat160601Senior Postmen (BOI14_postmen)C++14
38 / 100
1085 ms17452 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second int n,u,v,m,vis[500007],hav[500007]; vector < pair<int,int> > edge[500007]; stack <int> res; vector <int> ans; void dfs(int k){ stack <int> st; st.push(k); while(!st.empty()){ int u=st.top(),ok=0; for(int i=0;i<(int)edge[u].size();i++){ int v=edge[u][i].fi; int id=edge[u][i].se; if(vis[id]==1) continue; vis[id]=1; ok=1; st.push(v); break; } if(!ok){ ans.pb(u); st.pop(); } } } int main(){ scanf("%d %d",&n,&m); for(int i=1;i<=m;i++){ scanf("%d %d",&u,&v); edge[u].pb(mp(v,i)); edge[v].pb(mp(u,i)); } dfs(1); stack <int> stl; int el=0; for(int i=0;i<(int)ans.size();i++){ u=ans[i]; if(hav[u]){ if(el==1) printf("\n"); while(!stl.empty() && stl.top()!=u){ printf("%d ",stl.top()); hav[stl.top()]=0; stl.pop(); } printf("%d",u); el=1; } else{ hav[u]=1; stl.push(u); } } }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:32: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:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...