結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー rpy3cpprpy3cpp
提出日時 2017-04-05 01:29:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,389 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 95,736 KB
最終ジャッジ日時 2023-09-22 17:53:49
合計ジャッジ時間 17,239 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,276 KB
testcase_01 AC 16 ms
8,196 KB
testcase_02 AC 17 ms
8,048 KB
testcase_03 AC 18 ms
8,288 KB
testcase_04 AC 16 ms
8,176 KB
testcase_05 AC 17 ms
8,464 KB
testcase_06 AC 18 ms
8,300 KB
testcase_07 AC 17 ms
8,456 KB
testcase_08 AC 17 ms
8,516 KB
testcase_09 AC 17 ms
8,300 KB
testcase_10 AC 17 ms
8,308 KB
testcase_11 AC 18 ms
8,308 KB
testcase_12 AC 17 ms
8,428 KB
testcase_13 AC 17 ms
8,384 KB
testcase_14 AC 26 ms
9,184 KB
testcase_15 AC 26 ms
9,208 KB
testcase_16 AC 26 ms
9,108 KB
testcase_17 AC 26 ms
9,064 KB
testcase_18 AC 25 ms
9,196 KB
testcase_19 AC 26 ms
9,040 KB
testcase_20 AC 26 ms
9,240 KB
testcase_21 AC 26 ms
9,064 KB
testcase_22 AC 26 ms
9,164 KB
testcase_23 AC 26 ms
9,012 KB
testcase_24 AC 1,364 ms
95,484 KB
testcase_25 AC 1,371 ms
95,608 KB
testcase_26 AC 1,380 ms
95,736 KB
testcase_27 AC 1,389 ms
95,640 KB
testcase_28 AC 1,369 ms
95,600 KB
testcase_29 AC 1,379 ms
95,628 KB
testcase_30 AC 1,389 ms
95,696 KB
testcase_31 AC 1,366 ms
95,424 KB
testcase_32 AC 1,388 ms
95,564 KB
testcase_33 AC 1,370 ms
95,352 KB
testcase_34 AC 333 ms
56,128 KB
testcase_35 AC 20 ms
8,732 KB
testcase_36 AC 16 ms
8,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys

def read_data():
    N, M = map(int, input().split())
    Es = [[] for v in range(N)]
    EEs = [[] for v in range(N)]
    for line in sys.stdin:
        A, B, C = map(int, line.split())
        Es[A].append((B, C))
        EEs[B].append((A, C))
    return N, M, Es, EEs


def solve(N, M, Es, EEs):
    T1s = getTs(N, M, Es, 0)
    T2s = getTs(N, M, EEs, N - 1)
    T = T1s[N - 1]
    P = 0
    for t1, t2 in zip(T1s, T2s):
        if t1 + t2 < T:
            P += 1
    return '{} {}/{}'.format(T, P, N)


def getTs(N, M, Es, start):
    # n_ins[p]: p に入る辺の本数。
    n_ins = [0] * N
    for pairs in Es:
        for d, c in pairs:
            n_ins[d] += 1
    n_ins[start] = 1

    # Ts: 最早結合点時刻
    Ts = [-1] * N
    pq = [(0, start)]
    while pq:
        t, p = heapq.heappop(pq)
        n_ins[p] -= 1
        if n_ins[p]:
            continue
        Ts[p] = t
        for v, c in Es[p]:
            heapq.heappush(pq, (t + c, v))
    return Ts
    

N, M, Es, EEs = read_data()
print(solve(N, M, Es, EEs))   
0