#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=2e5+100;
const int mod=998244353;
//const int mod=(1ll<<61)-1;
using pii=pair<int,int>;
vector<pii>v[lim];
bool vis[lim];
vector<int>path;
void dfs(int node){
path.pb(node);
while(v[node].size()){
pii now=v[node].back();
v[node].pop_back();
if(vis[now.second])continue;
vis[now.second]=1;
dfs(now.first);
}
}
inline void solve(){
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++){
int x,y;
cin>>x>>y;
v[x].pb({y,i});
v[y].pb({x,i});
}
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;
}
}
if(1<cur.size()){
for(int j:cur){
cout<<j<<" ";
}cout<<"\n";
}
}
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 |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4952 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Incorrect |
3 ms |
5212 KB |
Edge does not exist or used 1, 41 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Incorrect |
2 ms |
5212 KB |
Edge does not exist or used 1, 41 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5468 KB |
Output is correct |
5 |
Incorrect |
2 ms |
5212 KB |
Edge does not exist or used 1, 41 |
6 |
Halted |
0 ms |
0 KB |
- |