結果

問題 No.2236 Lights Out On Simple Graph
ユーザー shobonvipshobonvip
提出日時 2023-03-04 01:29:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,723 ms / 4,000 ms
コード長 700 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 81,524 KB
実行使用メモリ 254,340 KB
最終ジャッジ日時 2023-10-18 04:05:00
合計ジャッジ時間 50,004 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,580 KB
testcase_01 AC 42 ms
55,580 KB
testcase_02 AC 42 ms
55,580 KB
testcase_03 AC 1,723 ms
254,024 KB
testcase_04 AC 1,303 ms
223,888 KB
testcase_05 AC 42 ms
55,584 KB
testcase_06 AC 1,382 ms
254,220 KB
testcase_07 AC 1,445 ms
175,328 KB
testcase_08 AC 42 ms
55,584 KB
testcase_09 AC 42 ms
55,584 KB
testcase_10 AC 299 ms
132,064 KB
testcase_11 AC 135 ms
76,136 KB
testcase_12 AC 443 ms
128,624 KB
testcase_13 AC 91 ms
82,896 KB
testcase_14 AC 1,051 ms
161,324 KB
testcase_15 AC 85 ms
79,876 KB
testcase_16 AC 114 ms
88,180 KB
testcase_17 AC 187 ms
98,416 KB
testcase_18 AC 59 ms
66,604 KB
testcase_19 AC 171 ms
98,544 KB
testcase_20 AC 666 ms
170,352 KB
testcase_21 AC 175 ms
98,544 KB
testcase_22 AC 1,579 ms
254,276 KB
testcase_23 AC 1,463 ms
254,220 KB
testcase_24 AC 1,090 ms
162,716 KB
testcase_25 AC 275 ms
123,644 KB
testcase_26 AC 1,489 ms
254,172 KB
testcase_27 AC 656 ms
170,352 KB
testcase_28 AC 1,192 ms
223,944 KB
testcase_29 AC 175 ms
98,544 KB
testcase_30 AC 1,586 ms
254,276 KB
testcase_31 AC 1,584 ms
254,280 KB
testcase_32 AC 1,584 ms
254,280 KB
testcase_33 AC 1,630 ms
254,280 KB
testcase_34 AC 1,572 ms
254,340 KB
testcase_35 AC 1,433 ms
218,528 KB
testcase_36 AC 1,013 ms
180,840 KB
testcase_37 AC 1,426 ms
254,340 KB
testcase_38 AC 988 ms
109,104 KB
testcase_39 AC 897 ms
77,832 KB
testcase_40 AC 488 ms
128,936 KB
testcase_41 AC 157 ms
90,928 KB
testcase_42 AC 466 ms
142,624 KB
testcase_43 AC 82 ms
76,692 KB
testcase_44 AC 1,299 ms
157,248 KB
testcase_45 AC 1,616 ms
223,896 KB
testcase_46 AC 1,382 ms
161,116 KB
testcase_47 AC 1,324 ms
221,576 KB
testcase_48 AC 1,376 ms
177,776 KB
testcase_49 AC 1,460 ms
175,248 KB
testcase_50 AC 72 ms
68,660 KB
testcase_51 AC 294 ms
107,044 KB
testcase_52 AC 75 ms
71,368 KB
testcase_53 AC 42 ms
55,584 KB
testcase_54 AC 895 ms
133,280 KB
testcase_55 AC 975 ms
97,044 KB
testcase_56 AC 947 ms
87,000 KB
testcase_57 AC 1,051 ms
100,880 KB
testcase_58 AC 948 ms
83,180 KB
testcase_59 AC 917 ms
83,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n,m = map(int,input().split())
a = [0] * m
b = [0] * m
for i in range(m):
	a[i], b[i] = map(int,input().split())
	a[i] -= 1
	b[i] -= 1

c = list(map(int,input().split()))
q = 0
for i in range(n):
	q ^= c[i] << i

r = m - m//2
v = defaultdict(lambda: 10 ** 9)

for i in range(1 << r):
	cnt = 0
	h = 0
	for j in range(r):
		if (i >> j & 1):
			cnt += 1
			h ^= 1 << a[m // 2 + j]
			h ^= 1 << b[m // 2 + j]
	v[h] = min(v[h], cnt)

r2 = m//2
ans = 10 ** 9

for i in range(1 << r2):
	cnt = 0
	h = 0
	for j in range(r2):
		if (i >> j & 1):
			cnt += 1
			h ^= 1 << a[j]
			h ^= 1 << b[j]
	ans = min(ans, v[q ^ h] + cnt)

if ans >= 10 ** 7:
	print(-1)
else:
	print(ans)
0