結果
| 問題 | No.2236 Lights Out On Simple Graph | 
| コンテスト | |
| ユーザー |  srjywrdnprkt | 
| 提出日時 | 2023-03-02 13:28:30 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,359 bytes | 
| コンパイル時間 | 1,370 ms | 
| コンパイル使用メモリ | 118,500 KB | 
| 最終ジャッジ日時 | 2025-02-11 01:07:17 | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 WA * 1 | 
| other | AC * 37 WA * 20 | 
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>
using namespace std;
using ll = long long;
int main(){
    ll N, M, m, a, b, vtx, ans=1e9, c=0, mx;
    cin >> N >> M;
    m = M/2;
    vector<pair<ll, ll>> e(M);
    for (int i=0; i<M; i++){
        cin >> a >> b; a--; b--;
        e[i] = {a, b};
    }
    for (int i=0; i<N; i++){
        cin >> a;
        c |= a*(1LL<<i);
    }
    vector<pair<ll, ll>> v;
    map<ll, ll> mp;
    mx = 1<<m;
    for (int i=0; i<mx; i++){
        vtx = 0;
        for (int j=0; j<m; j++){
            if (i & (1<<j)){
                tie(a, b) = e[j];
                vtx ^= (1LL<<a); vtx ^= (1LL<<b);
            }
        }
        v.push_back({vtx, __builtin_popcount(i)});
    }
    mx = 1<<(M-m);
    for (int i=0; i<mx; i++){
        vtx = 0;
        for (int j=0; j<(M-m); j++){
            if (i & (1<<j)){
                tie(a, b) = e[m+j];
                vtx ^= (1LL<<a); vtx ^= (1LL<<b);
            }   
        }
        mp[vtx] = __builtin_popcount(i);
    }
    for (auto [vtx, cnt] : v){
        if (mp.count(vtx ^ c)) ans = min(ans, cnt+mp[vtx ^ c]);
    }
    if (ans == 1e9) ans = -1;
    cout << ans << endl;
    return 0;
}
            
            
            
        