// Problem: No.2236 Lights Out On Simple GraphNo.2236 熄灯简图 // Contest: yukicoder // URL: https://yukicoder.me/problems/no/2236 // Memory Limit: 512 MB // Time Limit: 4000 ms #include #define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define dbg(x) cout << #x << " = " << (x) << "\n"; #define popcount(x) __builtin_popcountll((x)) #define all(v) (v).begin(), (v).end() #define pb emplace_back #define x first #define y second using namespace std; typedef long long ll; typedef pair pll; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; int n, m; int st; void solve() { cin >> n >> m; vector edges(m); for (auto &e : edges) { cin >> e.x >> e.y; e.x--, e.y--; } for (int i = 0; i < n; i++) { int x; cin >> x; st |= x << i; } int nn = m / 2; map vis; for (int j = 0; j < (1 << nn); j++) { int state = 0; for (int k = 0; k < nn; k++) { if (j & (1 << k)) { int x = edges[k].x, y = edges[k].y; state ^= (1 << x); state ^= (1 << y); } } if (vis.count(state)) vis[state] = min(vis[state], popcount(j)); else vis[state] = popcount(j); } int rest = m - nn; int ans = -1; for (int j = 0; j < (1 << rest); j++) { int state = 0; for (int k = 0; k < rest; k++) { if (j & (1 << k)) { int x = edges[nn + k].x, y = edges[nn + k].y; state ^= (1 << x); state ^= (1 << y); } } if (vis.count(state ^ st)) { if (ans == -1) ans = vis[state ^ st] + popcount(j); else ans = min(vis[state ^ st] + popcount(j), ans); } } cout << ans << "\n"; } int main() { fastio; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }