Submission #418584

#TimeUsernameProblemLanguageResultExecution timeMemory
418584BertedSenior Postmen (BOI14_postmen)C++14
55 / 100
505 ms40752 KiB
#include <iostream> #include <vector> #define pii pair<int, int> #define fst first #define snd second using namespace std; const int INF = 1e9; int N, M; vector<pii> adj[500001]; bool inStack[500001]; bool used[500001]; int main() { cin.tie(0) -> sync_with_stdio(0); cin >> N >> M; for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; adj[u - 1].push_back({v - 1, i}); adj[v - 1].push_back({u - 1, i}); } for (int i = 0; i < N; i++) { vector<int> S; if (adj[i].size()) { inStack[i] = 1; S.push_back(i); while (S.size()) { int u = S.back(); //cerr << "TRV: " << u << "\n"; if (adj[u].size()) { int v = adj[u].back().fst, id = adj[u].back().snd; adj[u].pop_back(); if (used[id]) continue; used[id] = 1; if (inStack[v]) { //cerr << "CYC: " << v << "\n"; while (S.back() != v) { cout << S.back() + 1 << " "; inStack[S.back()] = 0; S.pop_back(); } cout << v + 1 << "\n"; } else {S.push_back(v); inStack[v] = 1;} } else {inStack[i] = 0; S.pop_back();} } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...