제출 #1026220

#제출 시각아이디문제언어결과실행 시간메모리
1026220VMaksimoski008어르신 집배원 (BOI14_postmen)C++17
100 / 100
280 ms74948 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 5e5 + 5; int n, m; vector<pii> graph[maxn+5]; vector<int> P, vis(maxn), cnt(maxn); void dfs(int u) { while(!graph[u].empty()) { auto [v, id] = graph[u].back(); graph[u].pop_back(); if(vis[id]) continue; vis[id] = 1; dfs(v); } cnt[u]++; P.push_back(u); if(cnt[u] == 2) { cout << u << " "; P.pop_back(); while(!P.empty() && P.back() != u) { cout << P.back() << " "; cnt[P.back()]--; P.pop_back(); } cnt[u]--; cout << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n >> m; for(int i=0; i<m; i++) { int a, b; cin >> a >> b; graph[a].push_back({ b, i }); graph[b].push_back({ a, i }); } dfs(1); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...