-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
58 lines (53 loc) · 1.22 KB
/
Copy pathD.cpp
File metadata and controls
58 lines (53 loc) · 1.22 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define X first
#define Y second
#define rep(x, y, z) for(ll (z) = (x); (z) < (y); (z)++)
int constexpr N = 1e5;
int constexpr MOD = 1e9 + 7;
int constexpr INF = 1e9;
int n, m, k;
vector<int> g[N];
bool mark[N];
int dep[N], pa[N];
vector<int> dfs(int v, int d, int p) {
mark[v] = true;
dep[v] = d;
pa[v] = p;
// cerr << v << ' ' << dep[v] << '\n';
for (auto u : g[v]) {
if (!mark[u]) {
auto vec = dfs(u, d + 1, v);
if (vec[0] != -1) return vec;
}
else if (dep[v] - dep[u] >= k) {
int vv = v;
vector<int> res = {v};
while (vv != u) {
vv = pa[vv];
res.push_back(vv);
}
return res;
}
}
return {-1};
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> m >> k;
rep (0, m, i) {
int v, u;
cin >> v >> u;
v--; u--;
g[v].push_back(u);
g[u].push_back(v);
}
auto res = dfs(0, 0, -1);
cout << res.size() << '\n';
for (auto v : res) {
cout << v + 1 << ' ';
}
return 0;
}