-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElements of cycle.cpp
More file actions
93 lines (88 loc) · 1.69 KB
/
Elements of cycle.cpp
File metadata and controls
93 lines (88 loc) · 1.69 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//AnkitCode99 here....
#include<bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)
using namespace std;
const ll sz=100005;
const ll szz=1000006;
ll n,m,t;
vl ar[sz];
ll sttime[sz], vis[sz];
vector<ll> ans;
ll dfs(ll node, ll par, ll time)
{
if(vis[node])//if already visited check if the difference in time is greater than k
{
if(abs(time-sttime[node])>t)
{
return 1;
}
else
{
return 0;
}
}
vis[node]=1;
sttime[node]=time;
ll st=0;
for(ll child:ar[node])
{
if(child==par)
continue;
st|=dfs(child, node, time+1);//kya iss node k dfs se hume cycle mili?
if(st==1)
{
ans.pb(child);
break;
}
}
return st;
}
int main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("IP.txt","r",stdin);
freopen("OP.txt","w",stdout);
#endif
cin>>n>>m>>t;
rep(i,0,m)
{
ll u,v;
cin>>u>>v;
ar[u].pb(v);
ar[v].pb(u);
}
dfs(1, 1, 1);
set<ll> store;
ll cycle_length=0;
for(auto it:ans)
{
if(store.find(it)!=store.end())
break;
store.insert(it);
cycle_length++;
}
store.clear();
cout<<cycle_length<<endl;
for(auto it:ans)
{
if(store.find(it)!=store.end())
break;
store.insert(it);
cout<<it<<" ";
}
}//Goodbye