#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];
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;
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;
}
}
}
}
if (N <= 10) {
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3004 KB |
Output is correct |
2 |
Correct |
0 ms |
3004 KB |
Output is correct |
3 |
Correct |
0 ms |
3004 KB |
Output is correct |
4 |
Correct |
0 ms |
3004 KB |
Output is correct |
5 |
Correct |
0 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3004 KB |
Output is correct |
2 |
Correct |
0 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
3004 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
3004 KB |
Output is correct |
2 |
Correct |
0 ms |
3004 KB |
Output is correct |
3 |
Correct |
6 ms |
3004 KB |
Output is correct |
4 |
Correct |
123 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
113 ms |
3004 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
3004 KB |
Output is correct |
2 |
Correct |
39 ms |
3004 KB |
Output is correct |
3 |
Execution timed out |
1000 ms |
3004 KB |
Execution timed out |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1000 ms |
3004 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
323 ms |
3004 KB |
Expected integer, but "no" found |
2 |
Halted |
0 ms |
0 KB |
- |