제출 #31560

#제출 시각아이디문제언어결과실행 시간메모리
31560Dat160601어르신 집배원 (BOI14_postmen)C++14
100 / 100
358 ms25368 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],cnt=0,ed[1000007],to[1000007],last[1000007],pre[1000007]; stack <int> res; vector <int> ans; inline void addedge(int u,int v,int i){ cnt++; to[cnt]=v; ed[cnt]=i; pre[cnt]=last[u]; last[u]=cnt; cnt++; to[cnt]=u; ed[cnt]=i; pre[cnt]=last[v]; last[v]=cnt; } inline void dfs(int k){ stack <int> st; st.push(k); while(!st.empty()){ int u=st.top(),ok=0; for(int i=last[u];i;i=pre[i]){ int v=to[i]; int id=ed[i]; last[u]=pre[i]; 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); addedge(u,v,i); } dfs(1); stack <int> stl; for(int i=0;i<(int)ans.size();i++){ u=ans[i]; if(hav[u]){ while(!stl.empty() && stl.top()!=u){ printf("%d ",stl.top()); hav[stl.top()]=0; stl.pop(); } printf("%d\n",u); } else{ hav[u]=1; stl.push(u); } } }

컴파일 시 표준 에러 (stderr) 메시지

postmen.cpp: In function 'int main()':
postmen.cpp:44: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:46: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...