結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー rlangevinrlangevin
提出日時 2024-01-08 00:57:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 117,456 KB
最終ジャッジ日時 2024-01-08 00:57:58
合計ジャッジ時間 15,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,608 KB
testcase_01 AC 40 ms
55,608 KB
testcase_02 AC 40 ms
55,608 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 156 ms
86,868 KB
testcase_24 AC 92 ms
81,196 KB
testcase_25 AC 190 ms
92,900 KB
testcase_26 AC 275 ms
101,124 KB
testcase_27 AC 210 ms
94,780 KB
testcase_28 AC 151 ms
88,364 KB
testcase_29 AC 229 ms
94,656 KB
testcase_30 AC 154 ms
88,356 KB
testcase_31 AC 137 ms
86,112 KB
testcase_32 AC 157 ms
90,048 KB
testcase_33 AC 289 ms
100,268 KB
testcase_34 AC 295 ms
98,572 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 154 ms
93,760 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 143 ms
100,560 KB
testcase_44 AC 137 ms
96,816 KB
testcase_45 AC 128 ms
94,288 KB
testcase_46 AC 61 ms
77,560 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import deque
def topsort(G):
    Q = deque()
    N = len(G)
    count = [0] * N
    for u in range(N):
        for v, _, _ in G[u]:
            count[v] += 1

    for u in range(N):
        if count[u] == 0:
            Q.append(u)
    anslst = []
    while Q:
        u = Q.pop()
        anslst.append(u)
        for v, _, _ in G[u]:
            count[v] -= 1
            if count[v] == 0:
                Q.append(v)
    return anslst


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

dp = [0] * (N + 1)
dp_sum = [0] * (N + 1)
dp[0] = 1
L = topsort(G)
if len(L) != N + 1:
    print("INF")
    exit()

mod = 10**9 + 7    
for u in L:
    for v, l, a in G[u]:
        dp[v] += dp[u] * a
        dp[v] %= mod
        dp_sum[v] += dp_sum[u] + dp[u] * l * a
        dp_sum[v] %= mod
        
print(dp_sum[-1])
0