Submission #1114519

#TimeUsernameProblemLanguageResultExecution timeMemory
1114519MisterReaperNewspapers (CEOI21_newspapers)C++17
9 / 100
221 ms524288 KiB
#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); std::vector<std::pair<int, int>> save(1 << N); 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; std::array<int, 3> ans = {10 * N, -1, -1}; 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, i, nmask}); } save[mask] = {ans[1], ans[2]}; return dp[mask] = ans[0]; }; int ans = dfs(dfs, (1 << N) - 1); if (ans >= 10 * N) { std::cout << "NO\n"; } else { std::cout << "YES\n"; std::cout << ans << '\n'; int mask = (1 << N) - 1; while (mask != 0) { std::cout << save[mask].first + 1 << ' '; mask = save[mask].second; } std::cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...