結果

問題 No.2236 Lights Out On Simple Graph
ユーザー minimumminimum
提出日時 2023-03-03 22:04:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,737 ms / 4,000 ms
コード長 1,190 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 81,632 KB
実行使用メモリ 261,704 KB
最終ジャッジ日時 2023-10-18 02:13:12
合計ジャッジ時間 53,700 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,476 KB
testcase_01 AC 39 ms
53,476 KB
testcase_02 AC 39 ms
53,476 KB
testcase_03 AC 1,658 ms
220,092 KB
testcase_04 AC 1,205 ms
212,000 KB
testcase_05 AC 38 ms
53,480 KB
testcase_06 AC 1,726 ms
261,696 KB
testcase_07 AC 1,737 ms
261,704 KB
testcase_08 AC 39 ms
53,480 KB
testcase_09 AC 40 ms
53,480 KB
testcase_10 AC 297 ms
104,316 KB
testcase_11 AC 132 ms
75,740 KB
testcase_12 AC 402 ms
117,600 KB
testcase_13 AC 85 ms
77,948 KB
testcase_14 AC 1,074 ms
167,552 KB
testcase_15 AC 77 ms
75,884 KB
testcase_16 AC 111 ms
87,508 KB
testcase_17 AC 166 ms
97,048 KB
testcase_18 AC 58 ms
66,472 KB
testcase_19 AC 165 ms
98,140 KB
testcase_20 AC 645 ms
166,276 KB
testcase_21 AC 167 ms
98,140 KB
testcase_22 AC 1,633 ms
261,696 KB
testcase_23 AC 1,614 ms
220,104 KB
testcase_24 AC 1,182 ms
212,032 KB
testcase_25 AC 266 ms
112,460 KB
testcase_26 AC 1,617 ms
261,696 KB
testcase_27 AC 568 ms
132,184 KB
testcase_28 AC 1,181 ms
212,024 KB
testcase_29 AC 166 ms
98,140 KB
testcase_30 AC 1,636 ms
261,696 KB
testcase_31 AC 1,668 ms
261,696 KB
testcase_32 AC 1,669 ms
261,696 KB
testcase_33 AC 1,594 ms
220,100 KB
testcase_34 AC 1,672 ms
261,696 KB
testcase_35 AC 1,581 ms
226,224 KB
testcase_36 AC 1,280 ms
169,376 KB
testcase_37 AC 1,669 ms
261,704 KB
testcase_38 AC 931 ms
84,216 KB
testcase_39 AC 914 ms
77,572 KB
testcase_40 AC 549 ms
131,164 KB
testcase_41 AC 164 ms
98,140 KB
testcase_42 AC 361 ms
92,644 KB
testcase_43 AC 86 ms
75,428 KB
testcase_44 AC 1,423 ms
202,844 KB
testcase_45 AC 1,638 ms
261,704 KB
testcase_46 AC 1,590 ms
220,092 KB
testcase_47 AC 1,474 ms
224,088 KB
testcase_48 AC 1,537 ms
211,888 KB
testcase_49 AC 1,673 ms
261,684 KB
testcase_50 AC 73 ms
68,524 KB
testcase_51 AC 341 ms
135,512 KB
testcase_52 AC 76 ms
70,596 KB
testcase_53 AC 39 ms
53,480 KB
testcase_54 AC 1,180 ms
212,024 KB
testcase_55 AC 1,035 ms
94,708 KB
testcase_56 AC 981 ms
91,124 KB
testcase_57 AC 1,097 ms
114,348 KB
testcase_58 AC 1,019 ms
91,044 KB
testcase_59 AC 996 ms
98,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
edge0, edge1 = [], []
for i in range(M):
    a, b = map(int, input().split())
    if i % 2 == 0:
        edge0.append((a - 1, b - 1))
    else:
        edge1.append((a - 1, b - 1))

C = list(map(int, input().split()))
C.reverse()
goal = 0
for i in range(N):
    goal <<= 1
    goal |= C[i]

dic0 = dict()
for bit in range(1 << len(edge0)):
    state = 0
    cnt = 0
    for i in range(len(edge0)):
        if (bit >> i) & 1:
            cnt += 1
            state ^= (1 << edge0[i][0])
            state ^= (1 << edge0[i][1])
    if state not in dic0:
        dic0[state] = M
    if cnt < dic0[state]:
        dic0[state] = cnt

dic1 = dict()
for bit in range(1 << len(edge1)):
    state = 0
    cnt = 0
    for i in range(len(edge1)):
        if (bit >> i) & 1:
            cnt += 1
            state ^= (1 << edge1[i][0])
            state ^= (1 << edge1[i][1])
    if state not in dic1:
        dic1[state] = M
    if cnt < dic1[state]:
        dic1[state] = cnt

ans = M + 1
for i in dic0:
    if goal ^ i in dic1:
        if ans > dic1[goal ^ i] + dic0[i]:
            ans = dic1[goal ^ i] + dic0[i]

if ans == M + 1:
    print(-1)
else:
    print(ans)
0