제출 #1119676

#제출 시각아이디문제언어결과실행 시간메모리
1119676vjudge1어르신 집배원 (BOI14_postmen)C++17
0 / 100
2 ms760 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long int n, m; vector<vector<pair<int, int>>> a; bool kt[500005]; bool check[500005]; int l[500005], r[500005]; void get_ans(int u) { vector<int> ans; ans.push_back(u); vector<int> c; while (a[u].size()) { auto [v, id] = a[u].back(); a[u].pop_back(); if (kt[id] == true) continue; if (check[v] == true) { vector<int> res; res.clear(); while (!ans.empty() && ans.back() != v) { res.push_back(ans.back()); check[ans.back()] = false; ans.pop_back(); } res.push_back(v); reverse(res.begin(), res.end()); for (int i : res) { c.push_back(i); cout << i << " "; } cout << endl; // ans.pop_back(); u = v; kt[id] = true; continue; } kt[id] = true; check[v] = true; ans.push_back(v); u = v; } ans.pop_back(); for (int i : ans) { cout << i << " "; } if (ans.size()) cout << endl; for (int i : ans) { get_ans(i); } for (int i : c) { get_ans(i); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; a.assign(n + 1, {}); for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; l[i] = u; r[i] = v; a[u].push_back({v, i}); a[v].push_back({u, i}); } get_ans(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...