#include <bits/stdc++.h>
using namespace std;
int N,M, A[15], X;
vector<int> lst[15];
bitset<15> visited;
bool can;
void dfs (int x) {
visited[x] = true;
int num = 0;
for (int v: lst[x]) if (X & (1<<v)) num++;
if (num != 2) can = false;
for (int v: lst[x]) if ((X & (1<<v)) && !visited[v]) dfs(v);
}
void dfs2 (int x) {
visited[x] = true;
cout << x+1 << ' ';
for (int v: lst[x]) if ((X & (1<<v)) && !visited[v]) dfs2(v);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int u,v; cin >> u >> v; u--, v--;
lst[u].push_back(v), lst[v].push_back(u);
}
for (int i = 0; i < (1<<N); ++i) if (__builtin_popcount(i) >= 4) {
X = i, can = true;
visited.reset();
for (int j = 0; j < N; ++j) if (i & (1<<j)) {
dfs(j);
for (int k = 0; k < N; ++k) if ((i & (1<<k)) && !visited[k]) can = false;
if (can) {
visited.reset();
dfs2(j);
return 0;
}
else break;
}
}
cout << "no";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
844 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
484 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |