結果

問題 No.1480 Many Complete Graphs
ユーザー H3PO4H3PO4
提出日時 2022-07-23 11:58:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 104,084 KB
最終ジャッジ日時 2023-09-18 07:19:26
合計ジャッジ時間 18,487 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,520 KB
testcase_01 AC 71 ms
71,420 KB
testcase_02 AC 73 ms
71,528 KB
testcase_03 AC 72 ms
71,572 KB
testcase_04 AC 74 ms
71,428 KB
testcase_05 AC 72 ms
71,412 KB
testcase_06 AC 71 ms
71,476 KB
testcase_07 AC 72 ms
71,296 KB
testcase_08 AC 73 ms
71,468 KB
testcase_09 AC 83 ms
76,664 KB
testcase_10 AC 83 ms
76,608 KB
testcase_11 AC 78 ms
75,328 KB
testcase_12 AC 79 ms
76,024 KB
testcase_13 AC 102 ms
82,676 KB
testcase_14 AC 102 ms
81,176 KB
testcase_15 AC 220 ms
88,192 KB
testcase_16 AC 173 ms
85,152 KB
testcase_17 AC 174 ms
84,216 KB
testcase_18 AC 128 ms
81,908 KB
testcase_19 AC 181 ms
84,468 KB
testcase_20 AC 204 ms
85,800 KB
testcase_21 AC 103 ms
81,808 KB
testcase_22 AC 100 ms
80,188 KB
testcase_23 AC 134 ms
91,608 KB
testcase_24 AC 218 ms
89,024 KB
testcase_25 AC 283 ms
93,420 KB
testcase_26 AC 296 ms
95,988 KB
testcase_27 AC 223 ms
88,828 KB
testcase_28 AC 286 ms
102,772 KB
testcase_29 AC 289 ms
103,036 KB
testcase_30 AC 275 ms
101,308 KB
testcase_31 AC 277 ms
101,976 KB
testcase_32 AC 288 ms
101,988 KB
testcase_33 AC 279 ms
101,440 KB
testcase_34 AC 281 ms
103,028 KB
testcase_35 AC 281 ms
103,088 KB
testcase_36 AC 283 ms
102,436 KB
testcase_37 AC 285 ms
101,560 KB
testcase_38 AC 288 ms
102,752 KB
testcase_39 AC 284 ms
101,728 KB
testcase_40 AC 288 ms
101,136 KB
testcase_41 AC 287 ms
101,416 KB
testcase_42 AC 294 ms
103,036 KB
testcase_43 AC 291 ms
103,164 KB
testcase_44 AC 297 ms
101,288 KB
testcase_45 AC 301 ms
102,892 KB
testcase_46 AC 292 ms
101,768 KB
testcase_47 AC 402 ms
103,976 KB
testcase_48 AC 398 ms
104,084 KB
testcase_49 AC 396 ms
103,784 KB
testcase_50 AC 173 ms
97,824 KB
testcase_51 AC 410 ms
103,460 KB
testcase_52 AC 359 ms
102,400 KB
testcase_53 AC 346 ms
101,796 KB
testcase_54 AC 349 ms
102,264 KB
testcase_55 AC 343 ms
101,940 KB
testcase_56 AC 350 ms
101,988 KB
testcase_57 AC 177 ms
102,144 KB
testcase_58 AC 257 ms
102,876 KB
evil_aftercontest.txt AC 379 ms
128,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappop, heappush

input = sys.stdin.buffer.readline

N, M = map(int, input().split())
SIZE = N + 2 * M
G = [[] for _ in range(SIZE)]


def add_undirected_edge(u, v, c):
    G[u].append((v, c))
    G[v].append((u, c))


INF = 10 ** 18


def dijkstra(N, G, s):
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist


for m in range(N, SIZE, 2):
    K, C, *S = map(int, input().split())
    add_undirected_edge(m, m + 1, 1)
    for s in S:
        t = m + s % 2
        add_undirected_edge(s - 1, t, C + s)
dist = dijkstra(SIZE, G, 0)[N - 1]
print(-1 if dist == INF else dist // 2)
0