結果

問題 No.1480 Many Complete Graphs
ユーザー tamatotamato
提出日時 2021-04-16 20:52:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,380 KB
実行使用メモリ 106,384 KB
最終ジャッジ日時 2023-09-16 02:52:21
合計ジャッジ時間 18,157 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,132 KB
testcase_01 AC 78 ms
71,548 KB
testcase_02 AC 71 ms
71,248 KB
testcase_03 AC 73 ms
71,488 KB
testcase_04 AC 72 ms
71,400 KB
testcase_05 AC 72 ms
71,672 KB
testcase_06 AC 73 ms
71,208 KB
testcase_07 AC 74 ms
71,716 KB
testcase_08 AC 73 ms
71,704 KB
testcase_09 AC 100 ms
76,720 KB
testcase_10 AC 88 ms
77,216 KB
testcase_11 AC 79 ms
75,924 KB
testcase_12 AC 81 ms
76,660 KB
testcase_13 AC 112 ms
82,868 KB
testcase_14 AC 106 ms
81,660 KB
testcase_15 AC 247 ms
90,292 KB
testcase_16 AC 198 ms
86,476 KB
testcase_17 AC 196 ms
85,644 KB
testcase_18 AC 134 ms
82,548 KB
testcase_19 AC 198 ms
86,472 KB
testcase_20 AC 243 ms
88,580 KB
testcase_21 AC 119 ms
82,196 KB
testcase_22 AC 106 ms
80,456 KB
testcase_23 AC 159 ms
92,532 KB
testcase_24 AC 309 ms
94,088 KB
testcase_25 AC 346 ms
98,468 KB
testcase_26 AC 390 ms
100,500 KB
testcase_27 AC 322 ms
94,972 KB
testcase_28 AC 289 ms
105,144 KB
testcase_29 AC 302 ms
105,196 KB
testcase_30 AC 293 ms
106,272 KB
testcase_31 AC 294 ms
104,844 KB
testcase_32 AC 300 ms
105,236 KB
testcase_33 AC 287 ms
105,128 KB
testcase_34 AC 279 ms
106,336 KB
testcase_35 AC 281 ms
106,384 KB
testcase_36 AC 285 ms
106,044 KB
testcase_37 AC 301 ms
105,280 KB
testcase_38 AC 293 ms
105,324 KB
testcase_39 AC 294 ms
104,896 KB
testcase_40 AC 298 ms
106,316 KB
testcase_41 AC 295 ms
106,320 KB
testcase_42 AC 285 ms
106,360 KB
testcase_43 AC 297 ms
105,128 KB
testcase_44 AC 301 ms
105,332 KB
testcase_45 AC 297 ms
105,316 KB
testcase_46 AC 303 ms
104,912 KB
testcase_47 AC 447 ms
104,636 KB
testcase_48 AC 434 ms
104,728 KB
testcase_49 AC 435 ms
105,048 KB
testcase_50 AC 192 ms
97,596 KB
testcase_51 AC 446 ms
104,772 KB
testcase_52 AC 363 ms
104,776 KB
testcase_53 AC 368 ms
104,848 KB
testcase_54 AC 361 ms
104,620 KB
testcase_55 AC 361 ms
104,888 KB
testcase_56 AC 365 ms
104,584 KB
testcase_57 AC 204 ms
102,748 KB
testcase_58 AC 306 ms
105,552 KB
evil_aftercontest.txt AC 472 ms
135,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline
    import heapq
    def dijkstra(adj, start):
        # adj: [[to, cost] * vertices], 0th index must be empty
        inf = 1 << 60
        dist = [inf] * len(adj)
        dist[start] = 0
        q = []
        heapq.heappush(q, (0, start))
        while q:
            min_dist, v_from = heapq.heappop(q)
            if min_dist > dist[v_from]:
                continue
            v_tos = adj[v_from]
            for v_to, cost in v_tos:
                if min_dist + cost < dist[v_to]:
                    dist[v_to] = min_dist + cost
                    heapq.heappush(q, (dist[v_to], v_to))
        return dist

    N, M = map(int, input().split())
    adj = [[] for _ in range(N+1 + M * 2)]
    for m in range(1, M+1):
        KCS = list(map(int, input().split()))
        k, c = KCS[:2]
        for s in KCS[2:]:
            adj[s].append((N + m, (s + 1) // 2))
            adj[N + m].append((s, (s + 1) // 2 + c))
            if s & 1:
                adj[s].append((N + m + M, s // 2))
                adj[N + m + M].append((s, (s + 1) // 2 + c))
    ans = dijkstra(adj, 1)[N]
    if ans < 1 << 60:
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()
0