Submission #88744

#TimeUsernameProblemLanguageResultExecution timeMemory
88744popovicirobertSenior Postmen (BOI14_postmen)C++14
55 / 100
516 ms51496 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 using namespace std; const int MAXN = (int) 5e5; vector < pair <int, int> > g[MAXN + 1]; bool vis[MAXN + 1]; vector <int> ord; void dfs(int nod) { while(g[nod].size()) { auto it = g[nod].back(); g[nod].pop_back(); if(vis[it.second] == 0) { vis[it.second] = 1; dfs(it.first); } } ord.push_back(nod); } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n, m; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; for(i = 1; i <= m; i++) { int x, y; cin >> x >> y; g[x].push_back({y, i}); g[y].push_back({x, i}); } dfs(1); for(i = 1; i <= n; i++) { vis[i] = 0; } int sz = ord.size(); vector <int> stk; for(i = 0; i < sz; i++) { if(vis[ord[i]] == 0) { vis[ord[i]] = 1; stk.push_back(ord[i]); } else { while(stk.back() != ord[i]) { cout << stk.back() << " "; vis[stk.back()] = 0; stk.pop_back(); } cout << ord[i] << "\n"; } } //cout << ans; //cin.close(); //cout.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...