#include <bits/stdc++.h>
using namespace std;
#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl
#define fi first
#define se second
typedef pair<int, int> pii;
const int MaxN = 1010, MaxR = 1e5 + 10;
int n, r;
vector<pii> e[MaxN];
bool con[MaxN][MaxN];
pii edg[MaxR];
bool vis[MaxR], stk[MaxR];
//int pre[MaxR];
stack<int> path;
void dfs(int x, int y, int id) {
vis[id] = true;
stk[id] = true;
path.push(y);
for (pii z : e[y]) {
if (!con[x][z.fi] && z.fi != x) {
if (!vis[z.se]) {
//pre[z.se] = id;
dfs(y, z.fi, z.se);
} else if (stk[z.se]) {
//vector<int> cyc = {y};
//for (int u = id; cyc.size() == 1 || cyc.back() != y; u = pre[u])
// cyc.push_back(edg[u].fi + edg[u].se - cyc.back());
//cyc.pop_back();
//for (int i : path) TRACE(i);
vector<int> cyc = {path.top()};
for (path.pop(); path.top() != cyc[0]; path.pop())
cyc.push_back(path.top());
//for (int i : cyc) TRACE(i);
int m = cyc.size();
for (int len = 3; len < m; len++)
for (int i = 0; i < m; i++) {
if (con[cyc[i]][cyc[(i + len) % m]]) {
for (int j = (i + 1) % m; j != i; j = (j + 1) % m)
cout << cyc[j] << " ";
cout << cyc[i];
exit(0);
}
}
}
}
}
stk[id] = false;
path.pop();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> r;
for (int i = 0; i < r; i++) {
int x, y;
cin >> x >> y;
e[x].push_back({y, i});
e[y].push_back({x, i});
con[x][y] = con[y][x] = true;
edg[i] = {x, y};
}
for (int i = 0; i < r; i++) {
if (!vis[i]) {
path.push(edg[i].fi);
dfs(edg[i].fi, edg[i].se, i);
path.pop();
}
}
cout << "no";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
520 KB |
Output is correct |
2 |
Correct |
2 ms |
520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
664 KB |
Output is correct |
2 |
Correct |
2 ms |
664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
920 KB |
Output is correct |
2 |
Correct |
3 ms |
920 KB |
Output is correct |
3 |
Correct |
4 ms |
1176 KB |
Output is correct |
4 |
Correct |
4 ms |
1176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1176 KB |
Output is correct |
2 |
Correct |
3 ms |
1176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3048 KB |
Output is correct |
2 |
Incorrect |
10 ms |
3048 KB |
Repeated vertex |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
3048 KB |
Output is correct |
2 |
Correct |
11 ms |
3048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3824 KB |
Output is correct |
2 |
Correct |
75 ms |
3900 KB |
Output is correct |
3 |
Correct |
20 ms |
3900 KB |
Output is correct |
4 |
Correct |
33 ms |
3900 KB |
Output is correct |