1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #include <cstdio> #include <map> using namespace std; typedef long long L; const int N = 35; int n, m, ans = N; L ed, op[N]; map <L, int> f; void chkmin (int &x, int k) { if (k < x) x = k; } void dfs (int x, int y, L s, int t) { if (x == y) { if (y == n) { if (f.count(s)) chkmin(ans, f[s] + t); } else { if (f.count(s)) chkmin(f[s], t); else f[s] = t; } return; } dfs(x + 1, y, s ^ op[x], t + 1); dfs(x + 1, y, s, t); } int main() { scanf("%d%d", &n, &m); ed = (1ll << n) - 1; for (int i = 0; i < n; ++i) op[i] |= 1ll << i; for (int i = 1, a, b; i <= m; ++i) { scanf("%d%d", &a, &b); --a, --b; op[a] |= 1ll << b; op[b] |= 1ll << a; }
dfs(0, n >> 1, 0, 0); dfs(n >> 1, n, ed, 0); printf("%d", ans); return 0; }
|