結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー H3PO4H3PO4
提出日時 2020-08-25 09:37:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,092 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 132,916 KB
最終ジャッジ日時 2024-04-24 04:13:11
合計ジャッジ時間 25,143 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
11,008 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 34 ms
11,008 KB
testcase_03 AC 32 ms
10,880 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 32 ms
11,008 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 32 ms
10,880 KB
testcase_09 AC 32 ms
10,880 KB
testcase_10 AC 31 ms
10,880 KB
testcase_11 AC 35 ms
10,880 KB
testcase_12 AC 33 ms
10,880 KB
testcase_13 AC 32 ms
11,008 KB
testcase_14 AC 45 ms
12,032 KB
testcase_15 AC 46 ms
12,160 KB
testcase_16 AC 47 ms
12,160 KB
testcase_17 AC 45 ms
12,160 KB
testcase_18 AC 44 ms
12,032 KB
testcase_19 AC 46 ms
12,032 KB
testcase_20 AC 44 ms
12,288 KB
testcase_21 AC 46 ms
12,032 KB
testcase_22 AC 46 ms
12,032 KB
testcase_23 AC 45 ms
12,160 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 AC 816 ms
78,088 KB
testcase_35 AC 39 ms
11,520 KB
testcase_36 AC 32 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, defaultdict

input = sys.stdin.buffer.readline

def topological_sort(N, edges):
    outs = defaultdict(list)
    ins = defaultdict(int)
    for v1, v2, in edges:
        outs[v1].append(v2)
        ins[v2] += 1

    q = deque(v1 for v1 in range(N) if ins[v1] == 0)
    while q:
        v1 = q.popleft()
        yield v1
        for v2 in outs[v1]:
            ins[v2] -= 1
            if ins[v2] == 0:
                q.append(v2)


N, M = map(int, input().split())
edges = []
parents, children = [[] for _ in range(N)], [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges.append((a, b))
    parents[b].append((a, c))
    children[a].append((b, c))

tps = tuple(topological_sort(N, edges))
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