-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoundTrip.cpp
More file actions
48 lines (34 loc) · 806 Bytes
/
RoundTrip.cpp
File metadata and controls
48 lines (34 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>adj(100001);
vector<int>ans(100000);
int dfs(int x,int i,int indice,vector<bool>&check){
if(indice && x == i){return indice;}
check[x] = 0;
int a = 0;
for(int z : adj[x]){
ans[indice] = z;
a = a || dfs(z,i,indice+1,check);
if(a)break;
}
return a;
}
int main(){
int n,m;
cin >> n >> m;
while(m--){
int x,y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
int something = 0;
vector<bool>check(n+1,false);
for(int i = 1 ; i <= n ; i ++){
if(check[i])continue;
something = dfs(i,i,0,check);
if(something)break;
}
for(int i = 0 ; i < something ; i ++)cout << ans[i];
return 0;
}