Submission #465926

#TimeUsernameProblemLanguageResultExecution timeMemory
465926prvocisloSenior Postmen (BOI14_postmen)C++17
100 / 100
491 ms64144 KiB
#include <iostream> #include <vector> #include <list> #include <algorithm> typedef long long ll; using namespace std; const int maxn = 5e5 + 5; struct edge { int v, i; }; bool vise[maxn], visvr[maxn]; int nxt[maxn]; vector<edge> g[maxn]; vector<int> e; void dfs(int u) { if (visvr[u]) // cyklus { while (visvr[u]) { cout << u + 1 << " "; visvr[u] = false; u = nxt[u]; } cout << "\n"; } while (!g[u].empty()) { edge e = g[u].back(); g[u].pop_back(); if (!vise[e.i]) { vise[e.i] = true; visvr[u] = true; nxt[u] = e.v; dfs(e.v); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0, a, b; i < m; i++) { cin >> a >> b; a--, b--; g[a].push_back({ b, i }); g[b].push_back({ a, i }); } dfs(0); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...