P2962 [USACO09NOV]Lights Ghttps://www.luogu.com.cn/problem/P2962
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
#include <deque>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
int n, m;
ll v[50], t;
map<ll, int> mp;
int ans = INF;
void dfs(int st, int ed, ll now, int step) {
if (mp[now]) {
mp[now] = min(mp[now], step);
} else {
mp[now] = step;
}
if (mp[t ^ now] || t == now) {
ans = min(ans, mp[t ^ now] + mp[now]);
}
if (st > ed) {
return;
}
dfs(st + 1, ed, now, step);
now = now ^ v[st];
dfs(st + 1, ed, now, step + 1);
}
int main() {
int x, y;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d", &x, &y);
v[x] = v[x] ^ 1 << y;
v[y] = v[y] ^ 1 << x;
}
for (int i = 1; i <= n; i++) {
v[i] = v[i] ^ 1 << i;
t = t ^ 1 << i;
}
dfs(1, n / 2, 0, 0);
dfs(n / 2 + 1, n, 0, 0);
printf("%d", ans);
}