Submission #1057725

#TimeUsernameProblemLanguageResultExecution timeMemory
1057725andecaandeciSenior Postmen (BOI14_postmen)C++17
100 / 100
350 ms53364 KiB
#include <bits/stdc++.h> #define nikah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long #define pll pair<ll,ll> #define pb push_back #define pp pop_back #define fi first #define se second const ll maxn = 5e5+7, modn = 1e9+7; using namespace std; ll n,m,cur,tim; vector<pll>adj[maxn]; bool cekedge[maxn], ceknode[maxn]; stack<ll>s; void dfs(ll node) { if (ceknode[node]) { while (!s.empty()) { ll x = s.top(); ceknode[x] = 0; if (x == node) { cout<<x<<endl; break; } else { cout<<x<<" "; } s.pop(); } } else { s.push(node); } ceknode[node] = 1; while (!adj[node].empty() && cekedge[adj[node].back().se]) adj[node].pp(); if (adj[node].empty()) return; ll next = adj[node].back().fi, idx = adj[node].back().se; cekedge[idx] = 1; adj[node].pp(); dfs(next); } int main () { nikah cin>>n>>m; for (ll i=1; i<=m; i++) { ll u,v; cin>>u>>v; adj[u].pb({v,i}); adj[v].pb({u,i}); } for (ll i=1; i<=n; i++) { if (!adj[i].empty()) dfs(i); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...