제출 #1055613

#제출 시각아이디문제언어결과실행 시간메모리
1055613makanhulia어르신 집배원 (BOI14_postmen)C++17
100 / 100
417 ms57192 KiB
#include<bits/stdc++.h> using namespace std; #define int long long vector<pair<int,int> >adj[500002]; int sz[500002]; bool edge[500002]; bool node[500002]; stack<int>ans; void dfs(int q){ if(node[q]==true){ while(!ans.empty()){ int tmp=ans.top(); if(tmp==q){ cout<<q<<endl; break; } else{ cout<<tmp<<" "; node[tmp]=false; ans.pop(); } } } else{ ans.push(q); } node[q]=true; while(!adj[q].empty()&&edge[adj[q].back().second]==true){ adj[q].pop_back(); } if(!adj[q].empty()){ edge[adj[q].back().second]=true; sz[q]--; int has=adj[q].back().first; sz[has]--; adj[q].pop_back(); dfs(has); } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; int cnt=1; for(int q=1;q<=m;q++){ int u,v; cin>>u>>v; sz[u]++; sz[v]++; adj[u].push_back({v,cnt}); adj[v].push_back({u,cnt}); cnt++; } for(int q=1;q<=n;q++){ if(sz[q]>0){ dfs(q); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...