結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-01-22 22:30:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,642 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 128,824 KB
最終ジャッジ日時 2023-08-27 20:22:05
合計ジャッジ時間 14,428 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,404 KB
testcase_01 AC 94 ms
71,872 KB
testcase_02 AC 89 ms
71,612 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 177 ms
90,392 KB
testcase_24 AC 139 ms
84,420 KB
testcase_25 AC 303 ms
99,976 KB
testcase_26 AC 410 ms
113,276 KB
testcase_27 AC 279 ms
102,780 KB
testcase_28 AC 241 ms
95,080 KB
testcase_29 AC 270 ms
102,948 KB
testcase_30 AC 247 ms
95,460 KB
testcase_31 AC 211 ms
92,460 KB
testcase_32 AC 233 ms
95,472 KB
testcase_33 AC 388 ms
110,528 KB
testcase_34 AC 372 ms
108,808 KB
testcase_35 AC 308 ms
110,340 KB
testcase_36 AC 280 ms
108,280 KB
testcase_37 AC 213 ms
99,540 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 219 ms
111,644 KB
testcase_44 AC 179 ms
103,248 KB
testcase_45 AC 204 ms
111,664 KB
testcase_46 AC 97 ms
79,788 KB
testcase_47 AC 88 ms
71,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""


N~2N回目の間に頂点Nの更新があった場合はOUT
O(N)くらいで何とかする必要が…

Nからさかのぼり、行けない点を全部消す
あとはトポロジカルソートをして数え上げればよい

"""

import sys
from sys import stdin
from collections import deque

N,M = map(int,stdin.readline().split())
mod = 10**9+7

lis = [ [] for i in range(N+1) ]
rlis = [ [] for i in range(N+1) ]
inNum = [0] * (N+1)

for i in range(M):

    u,v,l,a = map(int,stdin.readline().split())
    lis[u].append((v,l,a))
    rlis[v].append(u)

exist = [0] * (N+1)
exist[N] = 1
q = deque([N])

while q:
    v = q.popleft()
    for nex in rlis[v]:
        if 0 == exist[nex]:
            exist[nex] = 1
            q.append(nex)

if not exist[0]:
    print (0)
    sys.exit()

q = deque([0])
exist[0] = 2

while q:
    v = q.popleft()
    for nex,tmp1,tmp2 in lis[v]:
        if 1 == exist[nex]:
            exist[nex] = 2
            q.append(nex)

for v in range(N+1):
    if exist[v] == 2:
        for nex,tmp1,tmp2 in lis[v]:
            inNum[nex] += 1


ans = [[0,0] for i in range(N+1)]
ans[0] = [0,1]

if inNum[0] != 0:
    print ("INF")
    sys.exit()

q = deque([0])

while q:
    
    v = q.popleft()
    if v == N:
        print (ans[N][0])
        #print (ans)
        sys.exit()

    for nex,l,a in lis[v]:
        if exist[nex] != 2:
            continue

        ans[nex][0] += ans[v][0] + ans[v][1] * a * l
        ans[nex][0] %= mod

        ans[nex][1] += ans[v][1] * a
        ans[nex][1] %= mod
        
        inNum[nex] -= 1
        if inNum[nex] == 0:
            q.append(nex)

print ("INF")
0