結果

問題 No.1480 Many Complete Graphs
ユーザー eijiroueijirou
提出日時 2021-04-17 15:49:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 495 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 108,512 KB
最終ジャッジ日時 2023-09-17 01:04:45
合計ジャッジ時間 20,522 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,392 KB
testcase_01 AC 71 ms
71,384 KB
testcase_02 AC 72 ms
71,348 KB
testcase_03 AC 73 ms
71,368 KB
testcase_04 AC 73 ms
71,156 KB
testcase_05 AC 77 ms
71,372 KB
testcase_06 AC 77 ms
71,280 KB
testcase_07 AC 74 ms
71,380 KB
testcase_08 AC 75 ms
71,400 KB
testcase_09 AC 83 ms
76,640 KB
testcase_10 AC 82 ms
76,576 KB
testcase_11 AC 77 ms
71,256 KB
testcase_12 AC 84 ms
76,756 KB
testcase_13 AC 103 ms
82,664 KB
testcase_14 AC 99 ms
81,148 KB
testcase_15 AC 273 ms
88,832 KB
testcase_16 AC 213 ms
85,144 KB
testcase_17 AC 200 ms
84,916 KB
testcase_18 AC 142 ms
82,648 KB
testcase_19 AC 212 ms
84,436 KB
testcase_20 AC 246 ms
85,160 KB
testcase_21 AC 107 ms
81,408 KB
testcase_22 AC 101 ms
80,220 KB
testcase_23 AC 139 ms
89,284 KB
testcase_24 AC 240 ms
85,888 KB
testcase_25 AC 355 ms
93,716 KB
testcase_26 AC 406 ms
97,984 KB
testcase_27 AC 251 ms
85,996 KB
testcase_28 AC 431 ms
108,044 KB
testcase_29 AC 450 ms
108,252 KB
testcase_30 AC 416 ms
105,544 KB
testcase_31 AC 424 ms
106,344 KB
testcase_32 AC 441 ms
107,488 KB
testcase_33 AC 417 ms
106,060 KB
testcase_34 AC 425 ms
108,512 KB
testcase_35 AC 411 ms
106,212 KB
testcase_36 AC 411 ms
105,832 KB
testcase_37 AC 405 ms
106,416 KB
testcase_38 AC 413 ms
105,864 KB
testcase_39 AC 409 ms
105,640 KB
testcase_40 AC 411 ms
106,184 KB
testcase_41 AC 409 ms
105,768 KB
testcase_42 AC 419 ms
108,392 KB
testcase_43 AC 412 ms
106,988 KB
testcase_44 AC 411 ms
107,088 KB
testcase_45 AC 442 ms
107,856 KB
testcase_46 AC 413 ms
106,384 KB
testcase_47 AC 482 ms
100,084 KB
testcase_48 AC 483 ms
100,184 KB
testcase_49 AC 483 ms
99,692 KB
testcase_50 AC 167 ms
91,364 KB
testcase_51 AC 495 ms
100,624 KB
testcase_52 AC 482 ms
104,288 KB
testcase_53 AC 483 ms
104,308 KB
testcase_54 AC 484 ms
104,636 KB
testcase_55 AC 480 ms
104,244 KB
testcase_56 AC 494 ms
104,252 KB
testcase_57 AC 175 ms
93,128 KB
testcase_58 AC 378 ms
100,708 KB
evil_aftercontest.txt AC 630 ms
120,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
from sys import stdin
input = stdin.readline

inf = 1 << 60

def main():
    n, m = map(int, input().split())
    edges = [[] for _ in range(n+m)]
    for i in range(n, n+m):
        k, c, *s = map(int, input().split())
        for j in s:
            edges[j-1].append((c, i))
            edges[i].append(j-1)
    
    # Dijkstra
    heap = []
    heappush(heap, (0, 0, 0))
    costs = [(inf,inf)] * (n+m)
    while heap:
        cost, rem, i = heappop(heap)
        if costs[i] < (cost,rem):
            continue
        if i < n:
            for c, j in edges[i]:
                new_cost = (cost + c + (i+1)//2, i+1 & 1)
                if new_cost < costs[j]:
                    costs[j] = new_cost
                    heappush(heap, (new_cost[0],new_cost[1],j))
        else:
            for j in edges[i]:
                new_cost = (cost + (j+rem+2)//2, 0)
                if new_cost < costs[j]:
                    costs[j] = new_cost
                    heappush(heap, (new_cost[0],new_cost[1],j))
    
    if costs[n-1] == (inf, inf):
        print(-1)
    else:
        print(costs[n-1][0])

main()
0