Submission #419619

#TimeUsernameProblemLanguageResultExecution timeMemory
419619VladMSenior Postmen (BOI14_postmen)C++14
55 / 100
1090 ms215928 KiB
#include <bits/stdc++.h> using namespace std; #define DIM 500007 int res, u, v, n, m, par[DIM], vis[DIM]; map<int, int> cnt[DIM]; vector<int> ans[DIM]; set<int> vec[DIM]; void dfs(int v, int p) { vis[v]=1; par[v]=p; for(auto to : vec[v]) { if(to==p) continue; if(vis[to]==1) { res++; vec[v].erase(to); vec[to].erase(v); while(v!=to) { p=par[v]; ans[res].push_back(v); vec[v].erase(p); vec[p].erase(v); vis[v]=0; par[v]=0; v=p; } ans[res].push_back(v); if(!vec[v].empty()) dfs(v, par[v]); } else dfs(to, v); break; } return; } int main() { cin>>n>>m; for(int i=1; i<=m; i++) { cin>>u>>v; vec[u].insert(v); vec[v].insert(u); cnt[v][u]++; cnt[u][v]++; if(cnt[v][u]==2) { res++; ans[res].push_back(u); ans[res].push_back(v); cnt[u][v]=0; vec[u].erase(v); vec[v].erase(u); } } for(int i=1; i<=n; i++) { if(vec[i].size()!=0) { dfs(i, -1); } } for(int i=1; i<=res; i++) { for(auto v : ans[i]) cout<<v<<' '; cout<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...