Submission #928590

#TimeUsernameProblemLanguageResultExecution timeMemory
928590tombSenior Postmen (BOI14_postmen)C++17
55 / 100
904 ms140060 KiB
#include<bits/stdc++.h> using namespace std; #define MAXN (int) 5e5 #define ll long long #define pb push_back #define eb emplace_back #define pil pair<int, ll> #define pli pair<ll, int> #define pll pair<ll, ll> #define vpli vector<pli> #define vpil vector<pil> #define vpll vector<pll> #define pii pair<int, int> #define vpii vector<pii> #define vi vector<int> #define vvi vector<vi> unordered_set<int> adj[MAXN]; int main(){ int n, m; cin >> n >> m; for (int i = 0; i < m; i++){ int u, v; cin >> u >> v; u--,v--; adj[u].insert(v); adj[v].insert(u); } stack<int> st; st.push(0); vvi paths; // vi path; vi vis; map<int, int> vis_idx; while (st.size()){ int u = st.top(); // if (vis.size() && u == vis.front()) // { // // reverse(vis.begin(), vis.end()); // paths.pb(vis); // vis.clear(); // } if (vis_idx.count(u) && vis_idx[u] != -1){ vi path; while (vis.size() && vis.back() != u){ path.pb(vis.back()); vis_idx[vis.back()] = -1; vis.pop_back(); } path.pb(u); reverse(path.begin(), path.end()); paths.pb(path); if (vis.size()) vis.pop_back(); } if (adj[u].size()){ vis.pb(u); vis_idx[u] = vis.size() - 1; auto v = adj[u].begin(); st.push(*v); adj[*v].erase(u); adj[u].erase(*v); } else { st.pop(); // path.pb(u); } } // cout << "ans: " << endl; for (auto p : paths){ if (p.size() == 1) continue; for (int i : p) cout << i + 1 << " "; cout << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...