이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |