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 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);
}
std::vector<int> dp(1 << N, -1);
dp[0] = 0;
auto dfs = [&](auto&& self, int mask) -> int {
if (dp[mask] != -1) {
return dp[mask] == -2 ? 10 * N : dp[mask];
}
dp[mask] = -2;
int ans = 10 * N;
for (int i = 0; i < N; ++i) {
int nmask = 0;
for (int j = 0; j < N; ++j) {
if (mask >> j & 1 && i != j) {
for (auto u : adj[j]) {
nmask |= (1 << u);
}
}
}
debug(mask, nmask);
ans = std::min(ans, self(self, nmask) + 1);
}
return dp[mask] = ans;
};
int ans = dfs(dfs, (1 << N) - 1);
if (ans >= 10 * N) {
std::cout << "NO\n";
} else {
std::cout << "YES\n";
std::cout << ans << '\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... |