結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー chineristACchineristAC
提出日時 2021-01-22 22:15:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 875 bytes
コンパイル時間 855 ms
コンパイル使用メモリ 86,980 KB
実行使用メモリ 121,612 KB
最終ジャッジ日時 2023-08-27 19:39:41
合計ジャッジ時間 16,565 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,724 KB
testcase_01 AC 94 ms
71,660 KB
testcase_02 AC 95 ms
71,688 KB
testcase_03 AC 95 ms
71,640 KB
testcase_04 AC 95 ms
71,384 KB
testcase_05 AC 96 ms
71,388 KB
testcase_06 AC 95 ms
71,608 KB
testcase_07 AC 96 ms
71,660 KB
testcase_08 AC 221 ms
78,708 KB
testcase_09 AC 121 ms
77,708 KB
testcase_10 AC 135 ms
78,056 KB
testcase_11 AC 141 ms
78,740 KB
testcase_12 AC 136 ms
78,592 KB
testcase_13 AC 393 ms
108,852 KB
testcase_14 AC 449 ms
108,944 KB
testcase_15 AC 471 ms
110,476 KB
testcase_16 AC 368 ms
101,172 KB
testcase_17 AC 244 ms
99,912 KB
testcase_18 AC 593 ms
121,612 KB
testcase_19 AC 600 ms
121,112 KB
testcase_20 AC 592 ms
120,992 KB
testcase_21 AC 603 ms
121,068 KB
testcase_22 AC 614 ms
120,912 KB
testcase_23 AC 178 ms
88,480 KB
testcase_24 AC 147 ms
83,956 KB
testcase_25 AC 226 ms
91,444 KB
testcase_26 AC 311 ms
103,016 KB
testcase_27 AC 260 ms
97,888 KB
testcase_28 AC 205 ms
90,552 KB
testcase_29 AC 250 ms
97,716 KB
testcase_30 AC 209 ms
90,712 KB
testcase_31 AC 189 ms
88,688 KB
testcase_32 AC 218 ms
93,256 KB
testcase_33 AC 294 ms
98,640 KB
testcase_34 AC 300 ms
100,852 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 204 ms
92,212 KB
testcase_38 AC 296 ms
104,732 KB
testcase_39 AC 296 ms
104,372 KB
testcase_40 AC 297 ms
104,776 KB
testcase_41 AC 298 ms
104,832 KB
testcase_42 AC 296 ms
104,784 KB
testcase_43 AC 198 ms
104,724 KB
testcase_44 AC 193 ms
102,444 KB
testcase_45 AC 176 ms
96,204 KB
testcase_46 AC 125 ms
93,588 KB
testcase_47 AC 93 ms
71,612 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 = [0 for i in range(N+1)]
dp[N] = 0
way = [0 for i in range(N+1)]
way[N] = 1
mod = 10**9+7

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

print(dp[0])
0