Submission #534809

#TimeUsernameProblemLanguageResultExecution timeMemory
534809Bill_00Senior Postmen (BOI14_postmen)C++14
55 / 100
567 ms86180 KiB
#include <bits/stdc++.h> #define N 500005 using namespace std; int vis[N], p[N]; int n, m, pre; set<int> adj[N]; vector<vector<int> > answer; vector<int> ans; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 1; i <= m; i++){ int a, b; cin >> a >> b; adj[a].insert(b); adj[b].insert(a); } for(int i = 1; i <= n; i++){ while(adj[i].size()){ stack<int> s; s.push(i); while(s.size()){ int now = s.top(); // cout << now << ' '; if(vis[now] == 1){ // cout << 1 << '\n'; ans.push_back(now); s.pop(); while(s.top() != now){ vis[s.top()] = 0; ans.push_back(s.top()); s.pop(); } vis[now] = 0; answer.push_back(ans); ans.clear(); } else{ if(adj[now].size() == 0){ vis[now] = 2; s.pop(); // cout << 2 << '\n'; } else{ // cout << 3 << '\n'; vis[now] = 1; int k = *adj[now].begin(); adj[now].erase(k); adj[k].erase(now); s.push(k); } } } } } for(vector<int> v : answer){ for(int k : v){ cout << k << ' '; } cout << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...