Submission #928577

#TimeUsernameProblemLanguageResultExecution timeMemory
928577tombSenior Postmen (BOI14_postmen)C++17
0 / 100
8 ms27740 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; while (st.size()){ int u = st.top(); if (vis.size() && u == vis.front()) { reverse(vis.begin(), vis.end()); paths.pb(vis); vis.clear(); } vis.pb(u); if (adj[u].size()){ 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){ 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...