Submission #861242

#TimeUsernameProblemLanguageResultExecution timeMemory
861242qwushaSenior Postmen (BOI14_postmen)C++17
0 / 100
24 ms1796 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second typedef long double ld; const ll inf = 1e9; const ld eps = 1e-8; vector<map<int, int>> cing; vector<set<int>> g; vector<vector<int>> ans; vector<bool> used; vector<int> cur; set<pair<int, int>> vert; void dfs(int v) { used[v] = 1; cur.push_back(v); for (auto u : g[v]) { if (vert.find({v, u}) == vert.end()) { continue; } vert.erase({v, u}); vert.erase({u, v}); if (used[u]) { vector<int> res; while(!cur.empty() && cur.back() != u) { res.push_back(cur.back()); used[cur.back()] = 0; cur.pop_back(); } if (!cur.empty()) { used[cur.back()] = 0; res.push_back(cur.back()); cur.pop_back(); } ans.push_back(res); if (!cur.empty()) { dfs(u); } else { dfs(v); } } else { dfs(u); cur.push_back(v); } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; used.resize(n); g.resize(n); cing.resize(n); for (int i = 0; i < m; i++) { int v, u; cin >> v >> u; if (v > u) swap(u, v); cing[v - 1][u - 1]++; } for (int v = 0; v < n; v++) { for (auto [u, cn] : cing[v]) { while (cn > 1) { cn -= 2; ans.push_back({v, u}); } if (cn == 1) { g[v].insert(u); g[u].insert(v); vert.insert({v, u}); vert.insert({u, v}); } } } dfs(0); for (auto s : ans) { for (auto el : s) { cout << el + 1 << ' '; } cout << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...