제출 #1104193

#제출 시각아이디문제언어결과실행 시간메모리
1104193VectorLi어르신 집배원 (BOI14_postmen)C++14
100 / 100
315 ms67256 KiB
#include <bits/stdc++.h> #define long long long using namespace std; const int V = (int) 5E5; const int E = (int) 5E5; int n, m; vector<pair<int, int>> e[V]; int t[E]; int c[V]; vector<int> a; void DFS(int u) { while (e[u].empty() == 0) { int v, i; tie(v, i) = e[u].back(); e[u].pop_back(); if (t[i] == 0) { t[i] = 1; DFS(v); } } a.push_back(u); c[u] = c[u] + 1; if (c[u] > 1) { cout << u + 1 << " "; c[u] = c[u] - 1; a.pop_back(); while (a.back() != u) { cout << a.back() + 1 << " "; c[a.back()] = c[a.back()] - 1; a.pop_back(); } cout << "\n"; } } void solve() { cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u = u - 1, v = v - 1; e[u].push_back({v, i}); e[v].push_back({u, i}); } DFS(0); } int main() { ios::sync_with_stdio(0); cin.tie(nullptr); int t; t = 1; for (int i = 0; i < t; i++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...