#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){
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);
}
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;
v[x].pb({y,i});
v[y].pb({x,i});
}
int left=m;
int now=1;
while(0<left){
if(size(v[now])){
dfs(now);
path.pop_back();
for(int i:path){
cout<<i<<" ";
}
cout<<"\n";
left-=path.size();
path.clear();
}else{
now++;
}
}
}
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 |
3 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
3 ms |
4956 KB |
Same junction appears twice in a route |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4952 KB |
Same junction appears twice in a route |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4956 KB |
Same junction appears twice in a route |
3 |
Halted |
0 ms |
0 KB |
- |