結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー chineristACchineristAC
提出日時 2021-01-22 22:06:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 816 bytes
コンパイル時間 1,773 ms
コンパイル使用メモリ 86,660 KB
実行使用メモリ 119,392 KB
最終ジャッジ日時 2023-08-27 19:20:10
合計ジャッジ時間 12,632 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,580 KB
testcase_01 AC 88 ms
71,640 KB
testcase_02 AC 86 ms
71,484 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 162 ms
88,520 KB
testcase_24 AC 133 ms
83,996 KB
testcase_25 AC 186 ms
91,348 KB
testcase_26 AC 256 ms
103,276 KB
testcase_27 AC 229 ms
97,632 KB
testcase_28 AC 180 ms
90,480 KB
testcase_29 AC 219 ms
97,968 KB
testcase_30 AC 176 ms
90,684 KB
testcase_31 AC 167 ms
88,376 KB
testcase_32 AC 196 ms
93,144 KB
testcase_33 AC 246 ms
98,548 KB
testcase_34 AC 252 ms
100,852 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 187 ms
92,240 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 176 ms
104,256 KB
testcase_44 AC 173 ms
101,592 KB
testcase_45 AC 160 ms
96,080 KB
testcase_46 WA -
testcase_47 AC 91 ms
71,676 KB
権限があれば一括ダウンロードができます

ソースコード

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