제출 #922289

#제출 시각아이디문제언어결과실행 시간메모리
922289AndrijaM어르신 집배원 (BOI14_postmen)C++14
100 / 100
458 ms65688 KiB
#include <bits/stdc++.h> using namespace std; const int maxn=5e5+10; int di[4]={1,-1,0,0}; int dj[4]={0,0,-1,1}; int n,m; bool vis[maxn]; int ma[maxn]; vector<pair<int,int>>g[maxn]; vector<int>path; void dfs(int node) { while(!g[node].empty()) { auto ax=g[node].back(); g[node].pop_back(); if(vis[ax.second])continue; vis[ax.second]=1; dfs(ax.first); } path.push_back(node); ma[node]++; if(ma[node]==2) { cout<<node+1<< " "; path.pop_back(); while(path.back()!=node) { cout<<path.back()+1<<" "; ma[path.back()]--; path.pop_back(); } cout<<endl; ma[node]=1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>m; memset(vis,0,sizeof vis); for(int i=0;i<m;i++) { int x,y; cin>>x>>y; x--;y--; g[x].push_back({y,i}); g[y].push_back({x,i}); } memset(ma,0,sizeof ma); dfs(0); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...