結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー H3PO4
提出日時 2020-11-24 21:47:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 877 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 121,640 KB
最終ジャッジ日時 2024-07-23 18:49:57
合計ジャッジ時間 25,604 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 21 TLE * 10
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

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