#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define ios ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
const int mod = 1e9 + 7;
const int INF = 1e9;
const double PI = acos(-1.0);
int n, m, a[N][N];
vector < int > g[N], vec;
int main() {
cin >> n >> m;
for (int i = 1, v, u; i <= m; ++i) {
cin >> v >> u;
a[v][u] = 1;
a[u][v] = 1;
g[v].push_back(u);
g[u].push_back(v);
}
for (int i = 1; i <= n; ++i)
vec.push_back(i);
do {
int ok = 1;
// int ko = 1;
// for (int i = 1; i <= n; ++i)
// if (vec[i - 1] != i)
// ko = 0;
for (int i = 1; i < n; ++i) {
if (a[vec[i]][vec[i - 1]] == 0) {
if (i - 1 >= 3 && a[vec[i - 1]][vec[0]]) {
for (int j = 0; j < i; ++j) {
cout << vec[j] << " ";
}
return 0;
}
ok = 0;
break;
}
for (int j = 1; j < i - 1; ++j) {
if (a[vec[i]][vec[j]]) {
ok = 0;
break;
}
}
}
if (ok && a[vec[0]][vec.back()]) {
for (int j : vec)
cout << j << " ";
return 0;
}
} while (next_permutation(vec.begin(), vec.end()));
cout << "no";
}
/**
clock() / (double)CLOCKS_PER_SEC < 1.9
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Incorrect |
3 ms |
384 KB |
Wrong answer on graph without induced cycle |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Wrong adjacency |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
512 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
768 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1058 ms |
768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1072 ms |
1536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1047 ms |
1536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
4856 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
4608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
52 ms |
3132 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |