結果

問題 No.2236 Lights Out On Simple Graph
ユーザー Kude
提出日時 2023-03-03 21:57:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 298 ms / 4,000 ms
コード長 1,513 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 222,424 KB
最終ジャッジ日時 2025-02-11 02:29:41
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<ll, char>> e0{{0, 0}}, e1{{0, 0}};
  rep(_, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ll x = 1LL << a | 1LL << b;
    int sz = e0.size();
    rep(i, sz) e0.emplace_back(e0[i].first ^ x, e0[i].second + 1);
    swap(e0, e1);
  }
  ll t = 0;
  rep(i, n) {
    int c;
    cin >> c;
    t |= ll(c) << i;
  }
  for(auto& [x, _]: e0) x ^= t;
  sort(all(e0));
  sort(all(e1));
  int j = 0;
  int ans = m + 1;
  rep(i, e0.size()) {
    while(j < e1.size() && e1[j].first < e0[i].first) j++;
    if (j == e1.size()) break;
    if (e1[j].first == e0[i].first) {
      chmin(ans, e0[i].second + e1[j].second);
    }
  }
  if (ans == m + 1) ans = -1;
  cout << ans << '\n';
}
0