結果
| 問題 | 
                            No.1364 [Renaming] Road to Cherry from Zelkova
                             | 
                    
| コンテスト | |
| ユーザー | 
                             rlangevin
                         | 
                    
| 提出日時 | 2024-01-08 00:57:42 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 968 bytes | 
| コンパイル時間 | 392 ms | 
| コンパイル使用メモリ | 82,252 KB | 
| 実行使用メモリ | 118,040 KB | 
| 最終ジャッジ日時 | 2024-09-27 19:33:53 | 
| 合計ジャッジ時間 | 13,304 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 WA * 28 | 
ソースコード
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])
            
            
            
        
            
rlangevin