제출 #714403

#제출 시각아이디문제언어결과실행 시간메모리
714403Stickfish어르신 집배원 (BOI14_postmen)C++17
100 / 100
429 ms45764 KiB
#include <iostream> #include <unordered_set> #include <algorithm> #include <cassert> #include <bitset> #include <vector> using namespace std; const int MAXN = 5e5 + 123; vector<int> edg[MAXN]; vector<int> find_euler_cycle() { vector<int> ans; vector<int> stck = {0}; while (stck.size()) { int v = stck.back(); if (edg[v].empty()) { ans.push_back(v); stck.pop_back(); } else { int u = edg[v].back(); edg[v].pop_back(); auto it = lower_bound(edg[u].begin(), edg[u].end(), v); if (it < edg[u].end() && *it == v) { stck.push_back(u); } } } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; edg[u].push_back(v); edg[v].push_back(u); } for (int i = 0; i < n; ++i) sort(edg[i].begin(), edg[i].end()); vector<int> ans = find_euler_cycle(); //for (auto x : ans) //cout << x + 1 << ' '; //cout << endl; vector<int> stck; bitset<MAXN> used; for (auto x : ans) { vector<int> ccl; while (used[x]) { used[stck.back()] = 0; ccl.push_back(stck.back()); stck.pop_back(); } if (ccl.size()) { for (auto x : ccl) cout << x + 1 << ' '; cout << '\n'; } stck.push_back(x); used[x] = 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...