Submission #733339

#TimeUsernameProblemLanguageResultExecution timeMemory
733339TrunktySenior Postmen (BOI14_postmen)C++14
55 / 100
553 ms143884 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll int n,m; set<int> roads[500005]; bool vis[500005]; vector<int> curr; vector<vector<int>> ans; void euler(int x){ if(vis[x]){ curr = {x}; return; } vis[x] = true; while(roads[x].size()>0){ int p = *roads[x].begin(); roads[x].erase(p); roads[p].erase(x); euler(p); if(curr.size()>0 and curr[0]!=x){ curr.push_back(x); vis[x] = false; return; } else if(curr[0]==x){ ans.push_back(curr); curr.clear(); } } } signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i=1;i<=m;i++){ int a,b; cin >> a >> b; roads[a].insert(b); roads[b].insert(a); } for(int i=1;i<=n;i++){ if(roads[i].size()>0){ euler(i); } } for(vector<int> i:ans){ for(int j:i){ cout << j << " "; } cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...