제출 #961028

#제출 시각아이디문제언어결과실행 시간메모리
961028noyancanturk어르신 집배원 (BOI14_postmen)C++17
100 / 100
421 ms78016 KiB
#ifndef Local #pragma GCC optimize("O3,unroll-loops") #endif #include "bits/stdc++.h" using namespace std; #define int int64_t #define pb push_back const int lim=5e5+100; const int mod=998244353; //const int mod=(1ll<<61)-1; using pii=pair<int,int>; vector<int>v[lim]; bool vis[2*lim]; vector<int>path; int to[2*lim]; void dfs(int node){ while(v[node].size()){ int now=v[node].back(); v[node].pop_back(); if(vis[now])continue; vis[now]=vis[now^1]=1; dfs(to[now]); } path.pb(node); } inline void solve(){ int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int x,y; cin>>x>>y; to[2*i]=y; to[2*i+1]=x; v[x].pb(2*i); v[y].pb(2*i+1); } dfs(1); vector<int>cur; bool seen[n+1]; memset(seen,0,sizeof(seen)); for(int j:path){ if(seen[j]){ cout<<j<<" "; while(cur.back()!=j){ cout<<cur.back()<<" "; seen[cur.back()]=0; cur.pop_back(); } cout<<"\n"; }else{ cur.push_back(j); seen[j]=1; } } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); #ifdef Local freopen(".in","r",stdin); freopen(".out","w",stdout); #endif 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...