結果

問題 No.2236 Lights Out On Simple Graph
ユーザー flygonflygon
提出日時 2023-03-04 18:35:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,270 ms / 4,000 ms
コード長 1,072 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 361,740 KB
最終ジャッジ日時 2023-10-18 04:39:10
合計ジャッジ時間 62,354 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
55,616 KB
testcase_01 AC 45 ms
55,616 KB
testcase_02 AC 45 ms
55,616 KB
testcase_03 AC 2,270 ms
360,896 KB
testcase_04 AC 1,714 ms
299,600 KB
testcase_05 AC 45 ms
55,620 KB
testcase_06 AC 1,841 ms
361,724 KB
testcase_07 AC 1,781 ms
271,752 KB
testcase_08 AC 45 ms
55,620 KB
testcase_09 AC 44 ms
55,620 KB
testcase_10 AC 402 ms
154,208 KB
testcase_11 AC 154 ms
76,300 KB
testcase_12 AC 599 ms
166,884 KB
testcase_13 AC 109 ms
93,268 KB
testcase_14 AC 1,225 ms
217,904 KB
testcase_15 AC 98 ms
88,056 KB
testcase_16 AC 125 ms
93,300 KB
testcase_17 AC 234 ms
118,804 KB
testcase_18 AC 64 ms
68,644 KB
testcase_19 AC 205 ms
122,560 KB
testcase_20 AC 932 ms
224,864 KB
testcase_21 AC 207 ms
122,584 KB
testcase_22 AC 2,141 ms
361,732 KB
testcase_23 AC 2,119 ms
361,488 KB
testcase_24 AC 1,240 ms
215,576 KB
testcase_25 AC 363 ms
164,380 KB
testcase_26 AC 2,077 ms
361,736 KB
testcase_27 AC 927 ms
224,880 KB
testcase_28 AC 1,439 ms
299,600 KB
testcase_29 AC 210 ms
122,580 KB
testcase_30 AC 2,128 ms
361,736 KB
testcase_31 AC 2,097 ms
361,740 KB
testcase_32 AC 2,173 ms
361,736 KB
testcase_33 AC 2,124 ms
361,736 KB
testcase_34 AC 2,231 ms
361,736 KB
testcase_35 AC 1,858 ms
288,696 KB
testcase_36 AC 1,357 ms
257,960 KB
testcase_37 AC 2,005 ms
361,728 KB
testcase_38 AC 1,068 ms
124,560 KB
testcase_39 AC 895 ms
79,692 KB
testcase_40 AC 678 ms
143,020 KB
testcase_41 AC 185 ms
101,800 KB
testcase_42 AC 622 ms
216,828 KB
testcase_43 AC 103 ms
80,236 KB
testcase_44 AC 1,504 ms
189,832 KB
testcase_45 AC 1,947 ms
297,808 KB
testcase_46 AC 1,686 ms
224,452 KB
testcase_47 AC 1,863 ms
282,316 KB
testcase_48 AC 1,825 ms
257,956 KB
testcase_49 AC 1,796 ms
271,756 KB
testcase_50 AC 82 ms
72,772 KB
testcase_51 AC 394 ms
147,184 KB
testcase_52 AC 93 ms
76,996 KB
testcase_53 AC 46 ms
55,624 KB
testcase_54 AC 1,005 ms
149,504 KB
testcase_55 AC 1,057 ms
118,864 KB
testcase_56 AC 1,003 ms
105,924 KB
testcase_57 AC 1,074 ms
117,512 KB
testcase_58 AC 984 ms
89,084 KB
testcase_59 AC 937 ms
91,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n,m = map(int,input().split())

graph = [[] for i in range(n+1)]
e = []
for i in range(m):
  a,b = map(int,input().split())
  graph[a].append(b)
  graph[b].append(a)
  e.append([a-1, b-1])

c = list(map(int,input().split()))
ini = 0
for i in range(n):
  if c[i]:
    ini |= (1<<i)

m1 = m//2
m2 = m - m1
e1,e2 = e[:m1], e[m1:]
d1, d2 = defaultdict(lambda : 10**15),defaultdict(lambda : 10**15)

s1,s2 = set(),set()
for i in range(2):
  for bit in range(1<<m1):
    now = 0
    cnt = 0
    for i in range(m1):
      if (bit >> i) & 1:
        now ^= 1<<e1[i][0]
        now ^= 1<<e1[i][1]
        cnt += 1
    s1.add(now)
    d1[now] = min(d1[now], cnt)
  m1,m2 = m2,m1
  e1,e2 = e2,e1
  s1,s2 = s2,s1
  d1,d2 = d2,d1

ans = 10**15
for i in s1:
  if (ini ^ i) in s2:
    ans = min(ans, d1[i] + d2[ini^i])

print(ans) if ans < 10**15 else print(-1)

0