This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
int lsb(int x) {
return x & -x;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
std::cin >> N >> M;
std::vector<std::vector<int>> adj(N);
for (int i = 0; i < M; ++i) {
int A, B;
std::cin >> A >> B;
--A, --B;
adj[A].emplace_back(B);
adj[B].emplace_back(A);
}
for (int m = 0; m < (1 << N); ++m) {
int popcnt = __builtin_popcount(m);
if (popcnt < 4) {
continue;
}
bool good = true;
for (int i = 0; i < N; ++i) {
if (m >> i & 1) {
int cnt = 0;
for (auto j : adj[i]) {
if (m >> j & 1) {
cnt += 1;
}
}
good &= cnt == 2;
}
}
if (good) {
int u = std::__lg(lsb(m)), v = std::__lg(lsb(m ^ (1 << u)));
for (int i = 0; i < popcnt; ++i) {
std::cout << u + 1 << ' ';
for (auto j : adj[u]) {
if (m >> j & 1) {
if (j != v) {
v = u;
u = j;
break;
}
}
}
}
return 0;
}
}
std::cout << "no\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |