제출 #1075080

#제출 시각아이디문제언어결과실행 시간메모리
1075080XJP12어르신 집배원 (BOI14_postmen)C++14
100 / 100
390 ms86864 KiB
#include<bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int,int> ii; typedef vector<ii> vii; typedef vector<vii> vvi; bitset<1000000> mp; vvi g; bitset<1000000> vis; vi indeg; int x=-1; void dfs(int u){ if(vis[u]==true){ x = u; cout<<u<<" "; vis[u]=false; return; } vis[u]=true; for(auto v: g[u]){ vis[u]=true; if(mp[v.second]!=1){ mp[v.second]=1; indeg[u]--; indeg[v.first]--; dfs(v.first); if(x!=-1 && x!=u){ // cout<<u<<endl; cout<<u<<" "; vis[u]=false; return; } if(x!=-1 && x==u){ //vis[u]=false; cout<<'\n'; x=-1; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; g.resize(n+1,vii()); indeg.resize(n+1,0); for(int i=0; i<m; i++){ int a,b; cin>>a>>b; if(a>b) swap(a,b); mp[i] = 0; indeg[a]++; indeg[b]++; g[a].push_back({b,i}); g[b].push_back({a,i}); } for(int i=1; i<=n; i++){ if(indeg[i]>0) dfs(i); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...