結果

問題 No.1480 Many Complete Graphs
ユーザー convexineqconvexineq
提出日時 2021-04-16 21:24:59
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 104,964 KB
最終ジャッジ日時 2023-09-16 02:54:20
合計ジャッジ時間 17,813 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,152 KB
testcase_01 AC 75 ms
71,340 KB
testcase_02 AC 74 ms
71,416 KB
testcase_03 AC 74 ms
71,232 KB
testcase_04 AC 72 ms
70,972 KB
testcase_05 AC 75 ms
71,020 KB
testcase_06 AC 75 ms
71,076 KB
testcase_07 AC 74 ms
70,976 KB
testcase_08 AC 76 ms
71,296 KB
testcase_09 AC 89 ms
76,460 KB
testcase_10 AC 89 ms
76,336 KB
testcase_11 AC 80 ms
75,260 KB
testcase_12 AC 80 ms
75,484 KB
testcase_13 AC 117 ms
82,796 KB
testcase_14 AC 114 ms
81,400 KB
testcase_15 AC 236 ms
89,068 KB
testcase_16 AC 197 ms
86,220 KB
testcase_17 AC 193 ms
84,884 KB
testcase_18 AC 136 ms
81,684 KB
testcase_19 AC 201 ms
85,372 KB
testcase_20 AC 221 ms
85,976 KB
testcase_21 AC 118 ms
81,996 KB
testcase_22 AC 111 ms
80,504 KB
testcase_23 AC 153 ms
89,964 KB
testcase_24 AC 233 ms
87,872 KB
testcase_25 AC 295 ms
93,276 KB
testcase_26 AC 313 ms
95,004 KB
testcase_27 AC 237 ms
88,064 KB
testcase_28 AC 325 ms
102,996 KB
testcase_29 AC 338 ms
102,928 KB
testcase_30 AC 332 ms
101,072 KB
testcase_31 AC 326 ms
101,740 KB
testcase_32 AC 331 ms
103,236 KB
testcase_33 AC 328 ms
101,588 KB
testcase_34 AC 326 ms
103,228 KB
testcase_35 AC 318 ms
101,520 KB
testcase_36 AC 314 ms
101,352 KB
testcase_37 AC 314 ms
101,640 KB
testcase_38 AC 314 ms
101,436 KB
testcase_39 AC 318 ms
101,520 KB
testcase_40 AC 316 ms
101,536 KB
testcase_41 AC 310 ms
101,732 KB
testcase_42 AC 322 ms
103,392 KB
testcase_43 AC 325 ms
101,768 KB
testcase_44 AC 329 ms
101,872 KB
testcase_45 AC 334 ms
101,996 KB
testcase_46 AC 332 ms
101,800 KB
testcase_47 AC 466 ms
104,964 KB
testcase_48 AC 460 ms
104,248 KB
testcase_49 AC 466 ms
104,036 KB
testcase_50 AC 221 ms
99,416 KB
testcase_51 AC 455 ms
104,412 KB
testcase_52 AC 393 ms
101,756 KB
testcase_53 AC 391 ms
101,944 KB
testcase_54 AC 397 ms
102,664 KB
testcase_55 AC 400 ms
102,032 KB
testcase_56 AC 412 ms
102,052 KB
testcase_57 AC 208 ms
103,700 KB
testcase_58 AC 306 ms
101,236 KB
evil_aftercontest.txt AC 473 ms
125,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
def dijkstra(g,start):
    n = len(g)
    INF = 1<<61
    dist = [INF]*(n) #startからの最短距離
    dist[start] = 0
    q = [(0,start)] #(そこまでの距離、点)
    while q:
        dv,v = heappop(q)
        if dist[v] < dv: continue
        for to, cost in g[v]:
            if dv + cost < dist[to]:
                dist[to] = dv + cost
                heappush(q, (dist[to], to))
    return dist

n,m = map(int,input().split())
g = [[] for _ in range(1+n+2*m)]
for i in range(m):
    k,c,*a = map(int,input().split())
    O = 2*i + n + 1
    E = 2*i + n + 2
    g[O].append((E,1))
    g[E].append((O,0))
    for ai in a:
        if ai%2:
            g[ai].append((O,ai//2+c))
            g[O].append((ai,ai//2+1))
        else:
            g[ai].append((E,ai//2+c))
            g[E].append((ai,ai//2))

dist = dijkstra(g,1)
print(dist[n] if dist[n] != 1<<61 else -1)
0