제출 #757783

#제출 시각아이디문제언어결과실행 시간메모리
757783taher어르신 집배원 (BOI14_postmen)C++17
100 / 100
484 ms112264 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> adj(n); vector<array<int, 2>> edges; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; adj[u].push_back(i); adj[v].push_back(i); edges.push_back({u, v}); } vector<vector<int>> tours; vector<bool> visited(m); vector<int> sBefore(n); vector<int> v; function<void(int)> Euler = [&](int head) { while ((int) adj[head].size() > 0) { auto u = adj[head].back(); adj[head].pop_back(); v.push_back(head); sBefore[head] += 1; if (!visited[u]) { visited[u] = true; int nxt = head ^ edges[u][0] ^ edges[u][1]; if (sBefore[nxt]) { vector<int> cur; int p = -1; do { cur.push_back(1 + v.back()); p = v.back(); sBefore[p] -= 1; v.pop_back(); } while (p != nxt); tours.push_back(cur); } Euler(nxt); } if ((int) v.size() > 0 && v.back() == head) { v.pop_back(); sBefore[head] -= 1; } } return ; }; Euler(0); for (int i = 0; i < (int) tours.size(); i++) { for (int j = 0; j < (int) tours[i].size(); j++) { cout << tours[i][j] << " \n"[j == (int) tours[i].size() - 1]; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...