結果

問題 No.2236 Lights Out On Simple Graph
ユーザー 👑 seekworserseekworser
提出日時 2023-03-02 20:47:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,186 ms / 4,000 ms
コード長 858 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 81,552 KB
実行使用メモリ 258,428 KB
最終ジャッジ日時 2023-10-17 18:44:22
合計ジャッジ時間 65,895 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,376 KB
testcase_01 AC 36 ms
53,376 KB
testcase_02 AC 37 ms
53,376 KB
testcase_03 AC 2,142 ms
257,972 KB
testcase_04 AC 945 ms
206,136 KB
testcase_05 AC 38 ms
53,496 KB
testcase_06 AC 1,444 ms
258,340 KB
testcase_07 AC 1,618 ms
141,124 KB
testcase_08 AC 37 ms
53,496 KB
testcase_09 AC 37 ms
53,496 KB
testcase_10 AC 441 ms
124,144 KB
testcase_11 AC 233 ms
75,984 KB
testcase_12 AC 517 ms
124,148 KB
testcase_13 AC 100 ms
81,604 KB
testcase_14 AC 1,024 ms
206,268 KB
testcase_15 AC 87 ms
79,096 KB
testcase_16 AC 105 ms
81,616 KB
testcase_17 AC 274 ms
97,876 KB
testcase_18 AC 55 ms
66,576 KB
testcase_19 AC 176 ms
89,560 KB
testcase_20 AC 923 ms
206,196 KB
testcase_21 AC 171 ms
89,560 KB
testcase_22 AC 2,070 ms
258,356 KB
testcase_23 AC 2,004 ms
258,392 KB
testcase_24 AC 1,064 ms
206,268 KB
testcase_25 AC 288 ms
97,872 KB
testcase_26 AC 2,015 ms
258,360 KB
testcase_27 AC 913 ms
206,224 KB
testcase_28 AC 1,080 ms
206,184 KB
testcase_29 AC 163 ms
89,560 KB
testcase_30 AC 2,030 ms
258,340 KB
testcase_31 AC 2,037 ms
258,340 KB
testcase_32 AC 2,166 ms
258,356 KB
testcase_33 AC 2,025 ms
258,356 KB
testcase_34 AC 2,038 ms
258,340 KB
testcase_35 AC 1,947 ms
258,388 KB
testcase_36 AC 2,186 ms
258,252 KB
testcase_37 AC 2,059 ms
258,428 KB
testcase_38 AC 2,101 ms
124,316 KB
testcase_39 AC 1,844 ms
79,236 KB
testcase_40 AC 778 ms
136,972 KB
testcase_41 AC 161 ms
89,560 KB
testcase_42 AC 446 ms
100,064 KB
testcase_43 AC 102 ms
78,904 KB
testcase_44 AC 1,921 ms
214,932 KB
testcase_45 AC 1,860 ms
207,884 KB
testcase_46 AC 1,925 ms
221,340 KB
testcase_47 AC 1,689 ms
227,984 KB
testcase_48 AC 2,113 ms
258,304 KB
testcase_49 AC 1,711 ms
141,064 KB
testcase_50 AC 93 ms
75,948 KB
testcase_51 AC 356 ms
88,396 KB
testcase_52 AC 84 ms
76,252 KB
testcase_53 AC 39 ms
53,496 KB
testcase_54 AC 944 ms
124,152 KB
testcase_55 AC 1,733 ms
97,864 KB
testcase_56 AC 1,375 ms
89,576 KB
testcase_57 AC 1,512 ms
99,836 KB
testcase_58 AC 1,525 ms
88,076 KB
testcase_59 AC 1,617 ms
89,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
a = []
b = []
for _ in range(m):
    ai, bi = map(int,input().split())
    a.append(ai-1)
    b.append(bi-1)
cv = list(map(int,input().split()))
c = 0
for i in range(n):
    if cv[i]:
        c += (1 << i)
seen = set()
val = dict()
m1 = m // 2
m2 = m - m1
for bt in range((1 << m1)):
    l = 0
    for i in range(m1):
        if (bt >> i) & 1:
            l ^= (1 << a[i])
            l ^= (1 << b[i])
    if l in seen:
        val[l] = min(val[l], bin(bt).count("1"))
    else:
        val[l] = bin(bt).count("1")
        seen.add(l)
ans = 100000000
for bt in range(1 << m2):
    l = c
    for i in range(m2):
        if (bt >> i) & 1:
            l ^= (1 << a[m1+i])
            l ^= (1 << b[m1+i])
    if l in seen:
        ans = min(ans, val[l] + bin(bt).count("1"))
if ans == 100000000:
    print(-1)
else:
    print(ans)
0