結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
71,512 KB
testcase_01 AC 100 ms
71,596 KB
testcase_02 AC 99 ms
71,492 KB
testcase_03 AC 99 ms
71,408 KB
testcase_04 AC 99 ms
71,280 KB
testcase_05 AC 96 ms
71,272 KB
testcase_06 AC 97 ms
71,400 KB
testcase_07 AC 98 ms
71,600 KB
testcase_08 AC 139 ms
78,596 KB
testcase_09 AC 123 ms
77,848 KB
testcase_10 AC 137 ms
78,472 KB
testcase_11 AC 140 ms
78,572 KB
testcase_12 AC 134 ms
78,620 KB
testcase_13 AC 386 ms
109,096 KB
testcase_14 AC 438 ms
108,880 KB
testcase_15 AC 451 ms
110,456 KB
testcase_16 AC 350 ms
101,100 KB
testcase_17 AC 236 ms
99,896 KB
testcase_18 AC 577 ms
121,488 KB
testcase_19 AC 557 ms
121,152 KB
testcase_20 AC 566 ms
120,680 KB
testcase_21 AC 567 ms
121,116 KB
testcase_22 AC 569 ms
120,920 KB
testcase_23 AC 173 ms
88,300 KB
testcase_24 AC 145 ms
83,768 KB
testcase_25 AC 218 ms
91,508 KB
testcase_26 AC 299 ms
103,088 KB
testcase_27 AC 255 ms
97,548 KB
testcase_28 AC 205 ms
90,220 KB
testcase_29 AC 240 ms
97,808 KB
testcase_30 AC 198 ms
90,576 KB
testcase_31 AC 186 ms
88,716 KB
testcase_32 AC 212 ms
92,956 KB
testcase_33 AC 282 ms
98,632 KB
testcase_34 AC 294 ms
100,928 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 200 ms
92,360 KB
testcase_38 AC 294 ms
104,720 KB
testcase_39 AC 292 ms
104,648 KB
testcase_40 AC 294 ms
104,756 KB
testcase_41 AC 288 ms
104,796 KB
testcase_42 AC 293 ms
104,552 KB
testcase_43 AC 199 ms
104,920 KB
testcase_44 AC 189 ms
102,120 KB
testcase_45 AC 171 ms
96,060 KB
testcase_46 WA -
testcase_47 AC 96 ms
71,440 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
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 dp[nv]!=-1:
            if dp[v]==-1:
                dp[v] = 0
            dp[v] += dp[nv] * a + l * a * way[nv]
            dp[v] %= mod
            way[v] += way[nv] * a
            way[v] %= mod

print(dp[0])
0