Submission #1084305

#TimeUsernameProblemLanguageResultExecution timeMemory
1084305teeslaSenior Postmen (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...