#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], used[N];
vector < int > g[N], vec;
inline void rec(int p) {
if (p >= 4) {
if (a[vec[1]][vec[p]] == 1) {
int ok = 1;
for (int i = 1; i + 1 <= p; ++i) {
int l = vec[i], r = vec[i + 1];
if (a[l][r] != 1) {
ok = 0;
break;
}
// cout << vec[i] << " ";
}
// cout << "\n";
if (ok)
for (int i = 1; i <= p; ++i) {
for (int j = 1; j + 1 < i; ++j) {
if (i == p && j == 1)
continue;
if (a[vec[i]][vec[j]]) {
ok = 0;
// cout << "WRONG " << vec[i] << " " << vec[j] << "\n";
break;
}
}
if (!ok)
break;
}
if (ok) {
for (int i = 1; i <= p; ++i) {
cout << vec[i] << " ";
}
exit(0);
}
}
}
for (int i = 1; i <= n; ++i) {
if (!used[i]) {
used[i] = 1;
vec.push_back(i);
rec(p + 1);
vec.pop_back();
used[i] = 0;
}
}
}
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);
}
vec.push_back(0);
rec(0);
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 |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
424 KB |
Output is correct |
2 |
Correct |
240 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
768 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1066 ms |
1664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1049 ms |
1664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1039 ms |
4804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1042 ms |
4608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1055 ms |
3068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |