제출 #1055762

#제출 시각아이디문제언어결과실행 시간메모리
1055762devariaota어르신 집배원 (BOI14_postmen)C++17
0 / 100
16 ms14828 KiB
#include <bits/stdc++.h> #define pb push_back #define int long long #define repp(i,x,n) for(int i=x;i<=n;i++) #define repo(i,x,n) for(int i=x;i>=n;i--) #define cy cout<<"Yes"<<endl #define cn cout<<"No"<<endl #define r0 return 0 #define fi first #define se second #define mp make_pair #define liow ios_base::sync_with_stdio(false);cin.tie(NULL) #define jelek cout<<"jelek"<<endl #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pi pair<pair<int,int>,pair<int,int>> #define p3 pair<int,pair<int,int>> #define p4 pair<pii,pii> #define fl fflush(stdout) #define lb long double using namespace std; const int mod2=1e9+7,mod=998244353,maxn=5e5+5,N=(1<<17),INF=1e18; vector<pii>adj[maxn]; bool visi[maxn]; vector<int>node; int ej[maxn]; int deg[maxn]; void dfs(int x){ // cout<<"x "<<":"<<x<<endl; node.pb(x); visi[x]=1; deg[x]--; for(pii i :adj[x]){ if(ej[i.se]) continue; deg[i.fi]--; if(visi[i.fi]){ // cout<<"anj "; // for(int i=0;i<node.size();i++){ // cout<<node[i]<<" "; // } // cout<<endl; int last=-1; if(deg[i.fi]>0) last=i.fi; while(!node.empty()){ cout<<node.back()<<" "; visi[node.back()]=0; if(last==-1) if(deg[node.back()]>0) last=node.back(); if(node.back()==i.fi){ node.pop_back(); break; } node.pop_back(); } cout<<endl; ej[i.se]=1; dfs(last); } else { ej[i.se]=1; dfs(i.fi); } } } void solve(){ int n,m;cin>>n>>m; repp(i,1,m){ int u,v;cin>>u>>v; adj[u].pb({v,i}); adj[v].pb({u,i}); deg[u]++; deg[v]++; } repp(i,1,n){ if(!visi[i]) dfs(i); } } signed main(){ liow; int t=1; // cin>>t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...