結果

問題 No.2236 Lights Out On Simple Graph
ユーザー roarisroaris
提出日時 2023-03-04 00:50:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,899 ms / 4,000 ms
コード長 890 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 258,644 KB
最終ジャッジ日時 2023-10-18 04:01:50
合計ジャッジ時間 53,430 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,464 KB
testcase_01 AC 41 ms
55,464 KB
testcase_02 AC 43 ms
55,464 KB
testcase_03 AC 1,899 ms
257,648 KB
testcase_04 AC 1,338 ms
227,420 KB
testcase_05 AC 42 ms
55,476 KB
testcase_06 AC 1,483 ms
257,724 KB
testcase_07 AC 1,483 ms
186,364 KB
testcase_08 AC 41 ms
55,476 KB
testcase_09 AC 43 ms
55,476 KB
testcase_10 AC 366 ms
113,692 KB
testcase_11 AC 149 ms
76,048 KB
testcase_12 AC 511 ms
132,704 KB
testcase_13 AC 97 ms
84,276 KB
testcase_14 AC 1,029 ms
172,204 KB
testcase_15 AC 90 ms
80,276 KB
testcase_16 AC 119 ms
85,324 KB
testcase_17 AC 198 ms
95,876 KB
testcase_18 AC 62 ms
68,576 KB
testcase_19 AC 182 ms
101,644 KB
testcase_20 AC 825 ms
175,328 KB
testcase_21 AC 183 ms
101,596 KB
testcase_22 AC 1,741 ms
258,300 KB
testcase_23 AC 1,653 ms
258,344 KB
testcase_24 AC 1,060 ms
160,312 KB
testcase_25 AC 307 ms
133,444 KB
testcase_26 AC 1,661 ms
258,368 KB
testcase_27 AC 804 ms
175,336 KB
testcase_28 AC 1,207 ms
211,576 KB
testcase_29 AC 181 ms
101,548 KB
testcase_30 AC 1,766 ms
257,924 KB
testcase_31 AC 1,768 ms
258,300 KB
testcase_32 AC 1,809 ms
258,300 KB
testcase_33 AC 1,777 ms
257,924 KB
testcase_34 AC 1,728 ms
258,300 KB
testcase_35 AC 1,412 ms
258,644 KB
testcase_36 AC 1,226 ms
167,348 KB
testcase_37 AC 1,549 ms
258,364 KB
testcase_38 AC 1,032 ms
109,040 KB
testcase_39 AC 875 ms
77,988 KB
testcase_40 AC 665 ms
117,408 KB
testcase_41 AC 165 ms
90,912 KB
testcase_42 AC 518 ms
153,788 KB
testcase_43 AC 104 ms
79,192 KB
testcase_44 AC 1,417 ms
160,324 KB
testcase_45 AC 1,618 ms
222,408 KB
testcase_46 AC 1,483 ms
168,356 KB
testcase_47 AC 1,511 ms
224,416 KB
testcase_48 AC 1,618 ms
190,932 KB
testcase_49 AC 1,501 ms
195,908 KB
testcase_50 AC 74 ms
70,624 KB
testcase_51 AC 347 ms
119,184 KB
testcase_52 AC 80 ms
73,336 KB
testcase_53 AC 45 ms
59,376 KB
testcase_54 AC 872 ms
124,940 KB
testcase_55 AC 1,043 ms
90,456 KB
testcase_56 AC 854 ms
89,656 KB
testcase_57 AC 893 ms
97,944 KB
testcase_58 AC 951 ms
83,920 KB
testcase_59 AC 902 ms
82,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(M)]
c = list(map(int, input().split()))
M1 = M//2
M2 = M-M1
pair = defaultdict(lambda: 10**18)

for S in range(1<<M1):
    mask = 0
    cnt = 0
    
    for i in range(M1):
        if (S>>i)&1:
            u, v = edges[i]
            mask ^= 1<<(u-1)
            mask ^= 1<<(v-1)
            cnt += 1
    
    for v in range(N):
        if c[v]==1:
            mask ^= 1<<v
    
    pair[mask] = min(pair[mask], cnt)

ans = 10**18

for S in range(1<<M2):
    mask = 0
    cnt = 0
    
    for i in range(M2):
        if (S>>i)&1:
            u, v = edges[M1+i]
            mask ^= 1<<(u-1)
            mask ^= 1<<(v-1)
            cnt += 1

    ans = min(ans, cnt+pair[mask])
        
if ans==10**18:
    print(-1)
else:
    print(ans)
0