Submission #88739

#TimeUsernameProblemLanguageResultExecution timeMemory
88739popovicirobertSenior Postmen (BOI14_postmen)C++14
0 / 100
17 ms12160 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 INF = 1e9; const int MAXN = (int) 5e5; vector < pair <int, int> > g[MAXN + 1]; int edge[MAXN + 1], now; int in_stk[MAXN + 1]; stack < pair <int, int> > stk; void dfs(int nod, int par, int id) { stk.push({nod, id}); in_stk[nod]++; for(auto it : g[nod]) { if(it.first == par) { continue; } if(edge[it.second] < now) { edge[it.second] = now; if(in_stk[it.first] == 0) { dfs(it.first, nod, it.second); } else { edge[it.second] = INF; while(stk.top().first != it.first) { cout << stk.top().first << " "; in_stk[stk.top().first]--; edge[stk.top().second] = INF; stk.pop(); } cout << it.first << "\n"; } } } } 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}); } for(i = 1; i <= n; i++) { while(!stk.empty()) { in_stk[stk.top().first] = 0; stk.pop(); } now++; dfs(i, 0, 0); } //cin.close(); //cout.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...