結果

問題 No.2236 Lights Out On Simple Graph
ユーザー titiatitia
提出日時 2023-03-05 01:59:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,235 ms / 4,000 ms
コード長 824 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 81,632 KB
実行使用メモリ 169,004 KB
最終ジャッジ日時 2023-10-18 04:46:10
合計ジャッジ時間 49,559 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,428 KB
testcase_01 AC 40 ms
53,428 KB
testcase_02 AC 47 ms
60,052 KB
testcase_03 AC 1,235 ms
168,988 KB
testcase_04 AC 690 ms
168,988 KB
testcase_05 AC 46 ms
60,052 KB
testcase_06 AC 813 ms
168,988 KB
testcase_07 AC 908 ms
101,960 KB
testcase_08 AC 39 ms
53,428 KB
testcase_09 AC 45 ms
60,108 KB
testcase_10 AC 766 ms
168,992 KB
testcase_11 AC 480 ms
75,608 KB
testcase_12 AC 822 ms
168,988 KB
testcase_13 AC 757 ms
168,996 KB
testcase_14 AC 899 ms
168,984 KB
testcase_15 AC 756 ms
168,996 KB
testcase_16 AC 795 ms
168,996 KB
testcase_17 AC 601 ms
136,176 KB
testcase_18 AC 637 ms
169,004 KB
testcase_19 AC 786 ms
168,992 KB
testcase_20 AC 848 ms
168,984 KB
testcase_21 AC 790 ms
168,992 KB
testcase_22 AC 1,103 ms
168,984 KB
testcase_23 AC 1,085 ms
168,988 KB
testcase_24 AC 924 ms
168,984 KB
testcase_25 AC 802 ms
168,992 KB
testcase_26 AC 1,059 ms
168,984 KB
testcase_27 AC 886 ms
168,988 KB
testcase_28 AC 930 ms
168,984 KB
testcase_29 AC 781 ms
168,992 KB
testcase_30 AC 1,125 ms
168,980 KB
testcase_31 AC 1,129 ms
168,988 KB
testcase_32 AC 1,124 ms
168,980 KB
testcase_33 AC 1,109 ms
168,984 KB
testcase_34 AC 1,113 ms
168,984 KB
testcase_35 AC 1,076 ms
168,984 KB
testcase_36 AC 1,112 ms
168,988 KB
testcase_37 AC 1,113 ms
168,980 KB
testcase_38 AC 980 ms
113,496 KB
testcase_39 AC 845 ms
77,360 KB
testcase_40 AC 762 ms
126,460 KB
testcase_41 AC 642 ms
102,040 KB
testcase_42 AC 679 ms
126,060 KB
testcase_43 AC 537 ms
91,104 KB
testcase_44 AC 1,176 ms
122,424 KB
testcase_45 AC 1,129 ms
122,676 KB
testcase_46 AC 1,149 ms
126,576 KB
testcase_47 AC 963 ms
126,088 KB
testcase_48 AC 1,202 ms
168,976 KB
testcase_49 AC 1,046 ms
101,960 KB
testcase_50 AC 465 ms
75,576 KB
testcase_51 AC 650 ms
101,960 KB
testcase_52 AC 516 ms
87,984 KB
testcase_53 AC 47 ms
62,092 KB
testcase_54 AC 862 ms
122,864 KB
testcase_55 AC 1,002 ms
97,792 KB
testcase_56 AC 743 ms
83,212 KB
testcase_57 AC 800 ms
90,484 KB
testcase_58 AC 902 ms
86,244 KB
testcase_59 AC 873 ms
83,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
E=[]
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    E.append((1<<a)^(1<<b))
C=list(map(int,input().split()))
now=0
for i in range(N):
    if C[i]==1:
        now^=(1<<i)

C=now

D=dict()
for i in range(1<<(min(20,M))):
    now=0
    c=0
    for j in range(min(20,M)):
        if i & (1<<j) != 0:
            now^=E[j]
            c+=1

    if now in D:
        D[now]=min(D[now],c)
    else:
        D[now]=c
    
if M<=20:
    if C in D:
        print(D[C])
    else:
        print(-1)
    exit()

ANS=1<<60

for i in range(1<<min(M-20,20)):
    now=0
    c=0
    for j in range(min(20,M-20)):
        if i & (1<<j) != 0:
            now^=E[j+20]
            c+=1

    if now^C in D:
        ANS=min(ANS,D[now^C]+c)

if ANS==1<<60:
    print(-1)
else:
    print(ANS)
0