結果

問題 No.2236 Lights Out On Simple Graph
ユーザー srjywrdnprkt
提出日時 2023-03-03 18:49:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 934 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 109,100 KB
最終ジャッジ日時 2025-02-11 01:41:00
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    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);
    }

   mx = 1LL<<M;
    for (ll i=0; i<mx; i++){
        vtx = 0;
        for (ll j=0; j<m; j++){
            if (i & (1LL<<j)){
                tie(a, b) = e[j];
                vtx ^= (1LL<<a); vtx ^= (1LL<<b);
            }
        }

        if ((c ^ vtx) == 0) ans = min(ans, (ll)__builtin_popcount(i));
    }

    if (ans == 1e9) ans = -1;
    cout << ans << endl;

    return 0;
}
0