제출 #1034665

#제출 시각아이디문제언어결과실행 시간메모리
1034665vjudge1어르신 집배원 (BOI14_postmen)C++17
0 / 100
10 ms23900 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << endl #define all(x) x.begin(),x.end() set<int> adj[500010]; bool vis[500010]; stack<int> st; int cnt=0; void dfs(int u,int p) { // debug(u); st.push(u); if(vis[u]) { cout<<st.top()<<' '; st.pop(); vis[u]=0; int prev=u; while(st.top()!=u) { cnt++; adj[prev].erase(adj[prev].find(st.top())); adj[st.top()].erase(adj[st.top()].find(prev)); cout<<st.top()<<' '; vis[st.top()]=0; prev=st.top(); st.pop(); } adj[prev].erase(adj[prev].find(u)); adj[u].erase(adj[u].find(prev)); cout<<'\n'; return; } vis[u]=1; for(auto i : adj[u]) { if(i!=p) { dfs(i,u); if(cnt--) return; if(adj[u].empty()) return; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m;cin>>n>>m; for(int i=0;i<m;i++) { int u,v;cin>>u>>v; adj[u].insert(v); adj[v].insert(u); } cout<<'\n'; for(int i=1;i<=n;i++) { while(adj[i].size()>0) dfs(i,-1); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...