結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー h_noson
提出日時 2017-06-16 00:02:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 81,912 KB
実行使用メモリ 117,660 KB
最終ジャッジ日時 2024-09-25 03:14:16
合計ジャッジ時間 8,641 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 31
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,m = map(int,input().split(' '))
e = [[] for i in range(n)]
re = [[] for i in range(n)]
di = [0] * n
for i in range(m):
    a,b,c = map(int,input().split(' '))
    e[a].append((b,c))
    re[b].append((a,c))
    di[b] += 1
q = deque()
for i in range(n):
    if di[i] == 0:
        q.append(i)
t = [0] * n
while len(q):
    u = q.popleft()
    for v,c in e[u]:
        t[v] = max(t[v],t[u] + c)
        di[v] -= 1
        if di[v] == 0:
            q.append(v)
q = deque()
q.append(n-1)
cp = [False] * n
cp[n-1] = True
while len(q):
    u = q.popleft()
    for v,c in re[u]:
        if not cp[v] and t[v] + c == t[u]:
            cp[v] = True
            q.append(v)
print(t[-1],"%d/%d" % (n-sum(cp),n))
0