結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-07 17:57:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 121,556 KB
最終ジャッジ日時 2024-04-26 15:04:42
合計ジャッジ時間 7,183 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,016 KB
testcase_01 AC 38 ms
54,272 KB
testcase_02 AC 39 ms
54,016 KB
testcase_03 AC 41 ms
55,040 KB
testcase_04 AC 39 ms
53,760 KB
testcase_05 AC 40 ms
54,528 KB
testcase_06 AC 41 ms
54,400 KB
testcase_07 AC 41 ms
54,656 KB
testcase_08 AC 40 ms
54,656 KB
testcase_09 AC 42 ms
54,656 KB
testcase_10 AC 41 ms
54,400 KB
testcase_11 AC 42 ms
54,656 KB
testcase_12 AC 40 ms
54,784 KB
testcase_13 AC 43 ms
54,440 KB
testcase_14 AC 70 ms
74,112 KB
testcase_15 AC 71 ms
74,752 KB
testcase_16 AC 70 ms
74,880 KB
testcase_17 AC 72 ms
74,972 KB
testcase_18 AC 68 ms
73,600 KB
testcase_19 AC 71 ms
75,136 KB
testcase_20 AC 70 ms
74,724 KB
testcase_21 AC 77 ms
77,608 KB
testcase_22 AC 79 ms
77,328 KB
testcase_23 AC 69 ms
74,496 KB
testcase_24 AC 361 ms
119,792 KB
testcase_25 AC 372 ms
120,484 KB
testcase_26 AC 361 ms
120,388 KB
testcase_27 AC 343 ms
119,496 KB
testcase_28 AC 380 ms
120,304 KB
testcase_29 AC 402 ms
121,556 KB
testcase_30 AC 381 ms
120,356 KB
testcase_31 AC 387 ms
121,212 KB
testcase_32 AC 366 ms
119,900 KB
testcase_33 AC 367 ms
120,912 KB
testcase_34 AC 137 ms
106,740 KB
testcase_35 AC 48 ms
56,960 KB
testcase_36 AC 42 ms
53,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def cycle_detectable_topological_sort(g, ind):
    V = len(g)
    order = []
    depth = [-1]*V
    for i in range(V):
        if not ind[i]:
            order.append(i)
            depth[i] = 0

    q = deque(order)
    while q:
        v = q.popleft()
        cur_depth = depth[v]
        for u in g[v]:
            ind[u] -= 1
            if not ind[u]:
                depth[u] = max(depth[u], cur_depth+1)
                q.append(u)
                order.append(u)
    if len(order) == V:
        return (order, depth)
    else:
        return (None, None)

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

INF = 10**18

n, m = map(int, input().split())
edge = [[] for i in range(n)]
rg = [[] for i in range(n)]
ind = [0]*n
for i in range(m):
    a, b, c = map(int, input().split())
    edge[a].append(b)
    rg[b].append((c, a))
    ind[b] += 1

order, _ = cycle_detectable_topological_sort(edge, ind)
dp1 = [-1]*n
dp1[0] = 0
for v in order:
    for c, u in rg[v]:
        dp1[v] = max(dp1[v], dp1[u]+c)
dp2 = [INF]*n
dp2[n-1] = dp1[n-1]
for v in reversed(order):
    for c, u in rg[v]:
        dp2[u] = min(dp2[u], dp2[v]-c)
#print(dp1)
#print(dp2)
ans = 0
for v in range(n):
    if dp1[v] != dp2[v]:
        ans += 1
print(dp1[v], str(ans)+'/'+str(n))
0