제출 #25990

#제출 시각아이디문제언어결과실행 시간메모리
25990H_H어르신 집배원 (BOI14_postmen)C++14
55 / 100
273 ms22932 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN=100005; bool vis[MAXN]; bool vs[MAXN]; set<int>adj[MAXN]; int n,m; int cyc=-1; void dfs(int x) { vis[x]=true; while(!adj[x].empty()) { int y=*adj[x].begin(); adj[x].erase(adj[x].begin()); adj[y].erase(adj[y].find(x)); if(vis[y]) { cout<<x; cyc=y; break; } dfs(y); if(cyc!=-1) { cout<<" "<<x; if(cyc==x) { cout<<endl; cyc=-1; } else break; } } vis[x]=false; } int main() { cin>>n>>m; for(int i=0;i<m;i++) { int x,y; cin>>x>>y; adj[x].insert(y); adj[y].insert(x); } for(int i=1;i<=n;i++)dfs(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...