結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー rlangevinrlangevin
提出日時 2023-12-20 12:25:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 560 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 130,412 KB
最終ジャッジ日時 2023-12-20 12:25:43
合計ジャッジ時間 10,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,604 KB
testcase_01 AC 53 ms
55,604 KB
testcase_02 AC 39 ms
55,604 KB
testcase_03 AC 41 ms
55,604 KB
testcase_04 AC 40 ms
55,604 KB
testcase_05 AC 41 ms
55,604 KB
testcase_06 AC 41 ms
55,604 KB
testcase_07 AC 41 ms
55,604 KB
testcase_08 AC 40 ms
55,604 KB
testcase_09 AC 41 ms
55,604 KB
testcase_10 AC 41 ms
55,604 KB
testcase_11 AC 41 ms
55,604 KB
testcase_12 AC 41 ms
55,604 KB
testcase_13 AC 42 ms
55,604 KB
testcase_14 AC 83 ms
76,992 KB
testcase_15 AC 80 ms
77,112 KB
testcase_16 AC 82 ms
77,096 KB
testcase_17 AC 81 ms
77,100 KB
testcase_18 AC 89 ms
77,000 KB
testcase_19 AC 82 ms
76,976 KB
testcase_20 AC 74 ms
74,408 KB
testcase_21 AC 82 ms
76,972 KB
testcase_22 AC 80 ms
76,968 KB
testcase_23 AC 83 ms
77,124 KB
testcase_24 AC 517 ms
129,260 KB
testcase_25 AC 533 ms
130,412 KB
testcase_26 AC 511 ms
128,492 KB
testcase_27 AC 535 ms
129,772 KB
testcase_28 AC 505 ms
130,028 KB
testcase_29 AC 560 ms
128,236 KB
testcase_30 AC 516 ms
130,028 KB
testcase_31 AC 507 ms
128,492 KB
testcase_32 AC 556 ms
130,284 KB
testcase_33 AC 505 ms
130,156 KB
testcase_34 AC 207 ms
115,948 KB
testcase_35 AC 48 ms
57,660 KB
testcase_36 AC 41 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import *
def topsort(G):
    Q = deque()
    N = len(G)
    count = [0] * N

    for u in range(N):
        for v in G[u]:
            count[v] += 1

    for u in range(N):
        if count[u] == 0:
            Q.append(u)
    anslst = deque()
    while Q:
        u = Q.pop()
        anslst.append(u)
        for v in G[u]:
            count[v] -= 1
            if count[v] == 0:
                Q.append(v)
    return list(anslst)


N, M = map(int, input().split())
G = [[] for i in range(N)]
GG = [[] for i in range(N)]
Gr = [[] for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    G[A].append((B, C))
    Gr[B].append((A, C))
    GG[A].append(B)

A = topsort(GG)
inf = 10 ** 18
dp, dpr = [-inf] * N, [inf] * N
dp[0] = 0
for a in A:
    for u, c in G[a]:
        dp[u] = max(dp[u], dp[a] + c) 

A.reverse()
dpr[-1] = dp[-1]
for a in A:
    for u, c in Gr[a]:
        dpr[u] = min(dpr[u], dpr[a] - c) 

cnt = 0
for i in range(N):
    cnt += int(dp[i]!=dpr[i])

ans = str(cnt) + "/" + str(N)
print(dp[-1], ans)
0