Submission #1027952

#TimeUsernameProblemLanguageResultExecution timeMemory
1027952anarch_ySenior Postmen (BOI14_postmen)C++17
100 / 100
308 ms65344 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) begin(x), end(x) #define sz(x) (int)x.size() #define pb push_back const int maxn = 500001; vector<pair<int, int>> adj[maxn]; vector<bool> seen; vector<int> path; void dfs(int s){ while(!adj[s].empty()){ auto [u, id] = adj[s].back(); adj[s].pop_back(); if(seen[id]) continue; seen[id] = true; dfs(u); } path.pb(s); } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; seen.resize(m+1); for(int i=1; i<=m; i++){ int a, b; cin >> a >> b; adj[a].pb({b, i}); adj[b].pb({a, i}); } dfs(1); reverse(all(path)); int v[n+1] = {}; vector<int> w; for(auto s: path){ if(v[s]){ cout << s << ' '; while(w.back() != s){ auto t = w.back(); w.pop_back(); v[t] = 0; cout << t << ' '; } cout << "\n"; } else{ v[s] = 1; w.pb(s); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...