제출 #31476

#제출 시각아이디문제언어결과실행 시간메모리
31476aome어르신 집배원 (BOI14_postmen)C++14
55 / 100
593 ms94212 KiB
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, m; set<int> G[N]; vector<int> euler; bool visit[N]; void dfs(int u) { while (G[u].size()) { int v = *G[u].begin(); G[u].erase(G[u].begin()), G[v].erase(G[v].find(u)); dfs(v); } euler.push_back(u); } int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; G[u].insert(v), G[v].insert(u); } dfs(1); vector<int> vCur; for (auto i : euler) { if (visit[i]) { vector<int> vNew; vNew.push_back(i); cout << i << ' '; while (vCur.back() != i) { int tmp = vCur.back(); cout << tmp << ' '; visit[tmp] = 0, vCur.pop_back(); } cout << '\n'; } else { vCur.push_back(i), visit[i] = 1; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...