#include <iostream>
#include <fstream>
#include <bitset>
#include <cassert>
#include <vector>
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF 1145141919
#define pb push_back
using namespace std;
int N, M;
bool G[1000][1000];
int U[10];
bool used[10];
int find(int x) {
if (U[x] == x) return x;
return U[x] = find(U[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
U[x] = y;
}
signed main() {
cin >> N >> M;
assert(N <= 10);
rep(i, M) {
int a, b;
cin >> a >> b;
a--, b--;
G[a][b] = G[b][a] = true;
}
rep(S, 1<<N) {
if (__builtin_popcount(S) < 4) continue;
rep(i, N) U[i] = i;
bool ok = true;
int hoe = -1;
rep(i, N) {
if (((S>>i)&1) == 0) continue;
hoe = i;
int deg = 0;
rep(t, N) if (G[i][t] && (S>>t)&1) unite(i, t), deg++;
if (deg != 2) {
ok = false;
break;
}
}
rep(i, N) if ((S>>i)&1) if (find(hoe) != find(i)) ok = false;
if (!ok) continue;
vector<int> vs;
int v = hoe;
used[v] = true;
vs.pb(v);
while (true) {
int to = -1;
rep(t, N) if (G[v][t] && (S>>t)&1 && !used[t]) to = t;
if (to == -1) break;
used[to] = true;
v = to;
vs.pb(v);
}
assert(vs.size() == __builtin_popcount(S));
for (int x : vs)cout<<x+1<< " ";cout<<"\n";
return 0;
}
cout << "no\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2992 KB |
Output is correct |
2 |
Correct |
0 ms |
2992 KB |
Output is correct |
3 |
Correct |
0 ms |
2992 KB |
Output is correct |
4 |
Correct |
0 ms |
2992 KB |
Output is correct |
5 |
Correct |
0 ms |
2992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2992 KB |
Output is correct |
2 |
Correct |
0 ms |
2992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2996 KB |
Execution killed because of forbidden syscall gettid (186) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2996 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2996 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2996 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2996 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2996 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2996 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |