제출 #1172924

#제출 시각아이디문제언어결과실행 시간메모리
1172924jill어르신 집배원 (BOI14_postmen)C++20
100 / 100
321 ms87988 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define pb push_back #define eb emplace_back #define se second typedef long long ll; using pii = pair<int, int>; const int nmax = 1e6 + 5; vector<pii> adj[nmax]; vector<int> path; int deg[nmax], vis[nmax], n, m; void dfs(int u) { while (!adj[u].empty()) { auto [son, idx] = adj[u].back(); adj[u].pop_back(); if (vis[idx]) continue; vis[idx] = 1; dfs(son); } path.pb(u); deg[u]++; if (deg[u] == 2) { cout << u << ' '; path.pop_back(); while (path.back() != u) { cout << path.back() << ' '; deg[path.back()]--; path.pop_back(); } cout << '\n'; deg[u] = 1; } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int u, v, i = 1; i <= m; i++) { cin >> u >> v; adj[u].pb({v, i}); adj[v].pb({u, i}); } dfs(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...