#include <iostream>
#include <fstream>
#include <bitset>
#include <cassert>
#include <vector>
#include <queue>
#include <algorithm>
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF 1145141919
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
int N, M;
bool G[1000][1000];
int A[1000], pre[1000];
signed main() {
cin >> N >> M;
rep(i, M) {
int a, b;
cin >> a >> b;
a--, b--;
G[a][b] = G[b][a] = true;
}
rep(s, N) {
rep(i, N) A[i] = -1;
queue<int> q;
rep(t, N) if (G[s][t]) {
pre[t] = s;
A[t] = t;
q.push(t);
}
while (!q.empty()) {
int x = q.front(); q.pop();
rep(t, N) if (G[x][t]) {
if (t == s) continue;
if (A[t] == -1) {
A[t] = A[x], pre[t] = x;
q.push(t);
}
else {
int a = A[x], b = A[t];
if (a == b || G[a][b]) continue;
vector<int> left, right;
while (x != s) {
left.pb(x);
x = pre[x];
}
while (t != s) {
right.pb(t);
t = pre[t];
}
reverse(all(right));
left.pb(s);
for (int r : right) left.pb(r);
for (int x : left) cout << x+1 << " "; cout << "\n";
return 0;
}
}
}
}
cout << "no\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3000 KB |
Output is correct |
2 |
Correct |
0 ms |
3000 KB |
Output is correct |
3 |
Correct |
0 ms |
3000 KB |
Output is correct |
4 |
Correct |
0 ms |
3000 KB |
Output is correct |
5 |
Correct |
0 ms |
3000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3000 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
3000 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
3000 KB |
Output is correct |
2 |
Correct |
3 ms |
3000 KB |
Output is correct |
3 |
Correct |
6 ms |
3000 KB |
Output is correct |
4 |
Correct |
126 ms |
3000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
116 ms |
3000 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
3000 KB |
Output is correct |
2 |
Correct |
49 ms |
3000 KB |
Output is correct |
3 |
Execution timed out |
1000 ms |
3000 KB |
Execution timed out |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
3000 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
333 ms |
3000 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |