Submission #485254

#TimeUsernameProblemLanguageResultExecution timeMemory
485254SirCovidThe19thSenior Postmen (BOI14_postmen)C++17
100 / 100
370 ms64100 KiB
#include <bits/stdc++.h> using namespace std; const int mx = 5e5 + 5; int n, m, pth[mx]; bool vis[mx], useEdg[mx]; vector<pair<int, int>> adj[mx]; void dfs(int cur){ if (vis[cur]){ int cyc = cur; while (vis[cyc]){ cout<<cyc<<" "; vis[cyc] = 0; cyc = pth[cyc]; } cout<<"\n"; } while (adj[cur].size()){ int nxt, ind; tie(nxt, ind) = adj[cur].back(); adj[cur].pop_back(); if (!useEdg[ind]){ useEdg[ind] = vis[cur] = 1; pth[cur] = nxt; dfs(nxt); } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++){ int a, b; cin >> a >> b; adj[a].push_back({b, i}); adj[b].push_back({a, i}); } dfs(1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...