Submission #1084312

#TimeUsernameProblemLanguageResultExecution timeMemory
1084312teeslaSenior Postmen (BOI14_postmen)C++17
100 / 100
293 ms83028 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> ii; vector<vector<ii>> adj; stack<int> res; vector<int> vis, edge; int dfs(int x){ vis[x] = 1; while(!adj[x].empty()){ auto [viz, idx] = adj[x].back(); adj[x].pop_back(); if(edge[idx]) continue; edge[idx] = 1; 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 <<"\n"; } else{ res.push(x); vis[x] = 0; return k; } } vis[x] = 0; return 0; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n >> m; adj.resize(n+2); vis.assign(n+2, 0); edge.assign(m+2,0); for(int i=0; i<m; i++){ int a,b; cin >> a >> b; adj[a].push_back({b,i}); adj[b].push_back({a,i}); } 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...