結果

問題 No.1480 Many Complete Graphs
ユーザー zkouzkou
提出日時 2021-04-16 21:53:42
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 719 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 119,192 KB
最終ジャッジ日時 2023-09-16 02:56:50
合計ジャッジ時間 23,925 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,532 KB
testcase_01 AC 73 ms
71,036 KB
testcase_02 AC 72 ms
71,508 KB
testcase_03 AC 73 ms
71,140 KB
testcase_04 AC 71 ms
71,028 KB
testcase_05 AC 74 ms
71,368 KB
testcase_06 AC 74 ms
71,260 KB
testcase_07 AC 74 ms
71,316 KB
testcase_08 AC 76 ms
71,316 KB
testcase_09 AC 101 ms
76,640 KB
testcase_10 AC 90 ms
76,508 KB
testcase_11 AC 80 ms
75,828 KB
testcase_12 AC 85 ms
76,184 KB
testcase_13 AC 152 ms
86,584 KB
testcase_14 AC 148 ms
84,832 KB
testcase_15 AC 287 ms
91,932 KB
testcase_16 AC 227 ms
87,804 KB
testcase_17 AC 223 ms
86,852 KB
testcase_18 AC 147 ms
82,680 KB
testcase_19 AC 240 ms
86,688 KB
testcase_20 AC 293 ms
90,012 KB
testcase_21 AC 152 ms
85,404 KB
testcase_22 AC 136 ms
79,624 KB
testcase_23 AC 192 ms
95,360 KB
testcase_24 AC 332 ms
98,972 KB
testcase_25 AC 400 ms
101,996 KB
testcase_26 AC 403 ms
104,524 KB
testcase_27 AC 352 ms
97,680 KB
testcase_28 AC 470 ms
114,148 KB
testcase_29 AC 488 ms
115,128 KB
testcase_30 AC 494 ms
113,832 KB
testcase_31 AC 500 ms
112,804 KB
testcase_32 AC 494 ms
114,328 KB
testcase_33 AC 476 ms
114,640 KB
testcase_34 AC 471 ms
115,488 KB
testcase_35 AC 465 ms
112,872 KB
testcase_36 AC 497 ms
112,456 KB
testcase_37 AC 497 ms
113,552 KB
testcase_38 AC 472 ms
114,124 KB
testcase_39 AC 479 ms
111,144 KB
testcase_40 AC 473 ms
113,452 KB
testcase_41 AC 465 ms
112,088 KB
testcase_42 AC 469 ms
115,236 KB
testcase_43 AC 488 ms
113,916 KB
testcase_44 AC 475 ms
113,536 KB
testcase_45 AC 486 ms
113,664 KB
testcase_46 AC 442 ms
112,220 KB
testcase_47 AC 719 ms
119,192 KB
testcase_48 AC 638 ms
117,264 KB
testcase_49 AC 658 ms
117,668 KB
testcase_50 AC 333 ms
110,192 KB
testcase_51 AC 682 ms
118,280 KB
testcase_52 AC 533 ms
113,940 KB
testcase_53 AC 573 ms
113,724 KB
testcase_54 AC 556 ms
113,428 KB
testcase_55 AC 549 ms
113,480 KB
testcase_56 AC 533 ms
112,536 KB
testcase_57 AC 313 ms
118,152 KB
testcase_58 AC 480 ms
118,692 KB
evil_aftercontest.txt AC 743 ms
160,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

N, M = map(int, input().split())

V = N + 4 * M + 1
new = N + 1
adj = [[] for _ in range(V + 1)]
for _ in range(M):
    k, c, *ss = map(int, input().split())
    s_even = [s for s in ss if s % 2 == 0]
    s_odd = [s for s in ss if s % 2 == 1]
    # even -> even
    for se in s_even:
        adj[se].append((new, se // 2))
        adj[new].append((se, c + se // 2))
    new += 1
    # even -> odd
    for se in s_even:
        adj[se].append((new, se // 2))
    for so in s_odd:
        adj[new].append((so, c + 1 + so // 2))
    new += 1
    # odd -> even
    for so in s_odd:
        adj[so].append((new, so // 2))
    for se in s_even:
        adj[new].append((se, c + 1 + se // 2))
    new += 1
    # odd -> odd
    for so in s_odd:
        adj[so].append((new, so // 2))
        adj[new].append((so, c + 1 + so // 2))
    new += 1

INF = 10 ** 18

pq = [(0, 1)]
dp = [INF] * V
dp[1] = 0
while pq:
    cost, v = heappop(pq)
    if cost > dp[v]:
        continue
    for nv, dist in adj[v]:
        if dp[nv] > dp[v] + dist:
            dp[nv] = dp[v] + dist
            heappush(pq, (dp[nv], nv))

ans = dp[N]
if ans == INF:
    ans = -1
print(ans)
0