結果

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

ソースコード

diff #

import sys
import graphlib

input = sys.stdin.buffer.readline

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}')
0