結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー H3PO4H3PO4
提出日時 2020-11-24 21:47:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,927 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 10,760 KB
実行使用メモリ 118,736 KB
最終ジャッジ日時 2023-10-01 01:14:55
合計ジャッジ時間 22,685 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,260 KB
testcase_01 AC 18 ms
8,224 KB
testcase_02 AC 17 ms
8,260 KB
testcase_03 AC 19 ms
8,356 KB
testcase_04 AC 17 ms
8,308 KB
testcase_05 AC 19 ms
8,300 KB
testcase_06 AC 18 ms
8,328 KB
testcase_07 AC 18 ms
8,460 KB
testcase_08 AC 18 ms
8,424 KB
testcase_09 AC 19 ms
8,336 KB
testcase_10 AC 19 ms
8,300 KB
testcase_11 AC 18 ms
8,448 KB
testcase_12 AC 19 ms
8,284 KB
testcase_13 AC 19 ms
8,428 KB
testcase_14 AC 30 ms
9,236 KB
testcase_15 AC 30 ms
9,224 KB
testcase_16 AC 31 ms
9,336 KB
testcase_17 AC 31 ms
9,192 KB
testcase_18 AC 30 ms
9,244 KB
testcase_19 AC 30 ms
9,224 KB
testcase_20 AC 30 ms
9,248 KB
testcase_21 AC 30 ms
9,224 KB
testcase_22 AC 30 ms
9,176 KB
testcase_23 AC 30 ms
9,240 KB
testcase_24 AC 1,926 ms
118,440 KB
testcase_25 AC 1,927 ms
118,576 KB
testcase_26 AC 1,926 ms
118,736 KB
testcase_27 AC 1,922 ms
118,572 KB
testcase_28 AC 1,917 ms
118,352 KB
testcase_29 AC 1,918 ms
118,596 KB
testcase_30 AC 1,907 ms
118,492 KB
testcase_31 AC 1,925 ms
118,344 KB
testcase_32 AC 1,922 ms
118,416 KB
testcase_33 AC 1,922 ms
118,356 KB
testcase_34 AC 1,011 ms
95,908 KB
testcase_35 AC 26 ms
9,156 KB
testcase_36 AC 18 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import graphlib

input = sys.stdin.buffer.readline

def solve():
    N, M = map(int, input().split())
    # Python 3.9 の新機能
    ts = graphlib.TopologicalSorter()
    parents, children = [[] for _ in range(N)], [[] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        # to, fromの順なので注意
        ts.add(b, a)
        parents[b].append((a, c))
        children[a].append((b, c))

    tps = tuple(ts.static_order())
    earliest, latest = [0] * N, [0] * N
    for x in tps:
        earliest[x] = max((earliest[p] + v for p, v in parents[x]), default=0)
    for x in reversed(tps):
        latest[x] = max((latest[c] + v for c, v in children[x]), default=0)

    T = earliest[N - 1]
    P = sum(earliest[x] + latest[x] != T for x in range(N))
    print(f'{T} {P}/{N}')


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