제출 #1084305

#제출 시각아이디문제언어결과실행 시간메모리
1084305teesla어르신 집배원 (BOI14_postmen)C++17
55 / 100
547 ms129860 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; vector<set<int>> adj; stack<int> res; vector<int> vis; int dfs(int x){ vis[x] = 1; while(!adj[x].empty()){ int viz = *adj[x].begin(); adj[x].erase(viz); adj[viz].erase(x); if(vis[viz]){ res.push(x); vis[x] = 0; return viz; } int k = dfs(viz); if(k == x){ res.push(x); while(!res.empty()){ if(res.top() != x) cout << ' '; cout << res.top(); res.pop(); } cout << endl; } else{ res.push(x); vis[x] = 0; return k; } } vis[x] = 0; return 0; } int main(){ int n,m; cin >> n >> m; adj.resize(n+2); vis.assign(n+2, 0); for(int i=0; i<m; i++){ int a,b; cin >> a >> b; adj[a].insert(b); adj[b].insert(a); } for(int i=1; i<=n; i++){ if(!adj[i].empty()) dfs(i); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...