Submission #1119665

#TimeUsernameProblemLanguageResultExecution timeMemory
1119665vjudge1Senior Postmen (BOI14_postmen)C++17
0 / 100
3 ms724 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<tuple<int, int, int> > er; vector<tuple<int, int, int> > re_add; 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; 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) { cout << i << " "; } cout << endl; ans.pop_back(); u = v; } 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); } } 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...