結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー chineristAC
提出日時 2021-01-22 22:06:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 816 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 119,016 KB
最終ジャッジ日時 2024-12-28 01:05:08
合計ジャッジ時間 11,681 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

import sys

input = sys.stdin.readline

N,M = map(int,input().split())
edge = [[] for i in range(N+1)]
deg = [0 for i in range(N+1)]
for i in range(M):
    u,v,l,a = map(int,input().split())
    edge[u].append((v,l,a))
    deg[v] += 1

res = []
deq = deque([v for v in range(N+1) if deg[v]==0])
while deq:
    v = deq.popleft()
    res.append(v)
    for nv,l,a in edge[v]:
        deg[nv] -= 1
        if not deg[nv]:
            deq.append(nv)

if 0 not in res or N not in res:
    exit(print("INF"))

dp = [-1 for i in range(N+1)]
dp[N] = 0
mod = 10**9+7

for v in res[::-1]:
    if v==N:
        continue
    for nv,l,a in edge[v]:
        if dp[nv]!=-1:
            if dp[v]==-1:
                dp[v] = 0
            dp[v] += a * (l+dp[nv])
            dp[v] %= mod

print(dp[0])
0