結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー convexineqconvexineq
提出日時 2021-01-23 12:44:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 825 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,668 KB
実行使用メモリ 123,260 KB
最終ジャッジ日時 2023-08-28 23:02:12
合計ジャッジ時間 15,446 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,012 KB
testcase_01 AC 71 ms
70,644 KB
testcase_02 AC 72 ms
71,112 KB
testcase_03 AC 73 ms
70,876 KB
testcase_04 AC 77 ms
70,808 KB
testcase_05 AC 72 ms
70,852 KB
testcase_06 AC 75 ms
70,924 KB
testcase_07 AC 74 ms
70,960 KB
testcase_08 AC 140 ms
78,432 KB
testcase_09 AC 115 ms
78,020 KB
testcase_10 AC 116 ms
78,316 KB
testcase_11 AC 109 ms
78,272 KB
testcase_12 AC 127 ms
78,156 KB
testcase_13 AC 276 ms
107,988 KB
testcase_14 AC 407 ms
117,840 KB
testcase_15 AC 361 ms
115,560 KB
testcase_16 AC 300 ms
103,944 KB
testcase_17 AC 171 ms
93,892 KB
testcase_18 AC 381 ms
123,192 KB
testcase_19 AC 380 ms
123,076 KB
testcase_20 AC 381 ms
122,960 KB
testcase_21 AC 382 ms
123,260 KB
testcase_22 AC 378 ms
123,144 KB
testcase_23 AC 172 ms
88,884 KB
testcase_24 AC 163 ms
86,188 KB
testcase_25 AC 304 ms
100,992 KB
testcase_26 AC 410 ms
111,572 KB
testcase_27 AC 337 ms
105,268 KB
testcase_28 AC 238 ms
93,100 KB
testcase_29 AC 326 ms
105,188 KB
testcase_30 AC 248 ms
93,040 KB
testcase_31 AC 194 ms
90,368 KB
testcase_32 AC 275 ms
99,772 KB
testcase_33 AC 409 ms
110,748 KB
testcase_34 AC 394 ms
109,844 KB
testcase_35 AC 335 ms
111,268 KB
testcase_36 AC 337 ms
110,344 KB
testcase_37 AC 257 ms
99,784 KB
testcase_38 AC 331 ms
115,876 KB
testcase_39 AC 333 ms
115,596 KB
testcase_40 AC 333 ms
115,828 KB
testcase_41 AC 331 ms
116,044 KB
testcase_42 AC 338 ms
115,720 KB
testcase_43 AC 231 ms
103,396 KB
testcase_44 AC 217 ms
110,988 KB
testcase_45 AC 209 ms
101,128 KB
testcase_46 AC 76 ms
76,304 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
n += 1
g = [[] for _ in range(n)]
edges = []
for _ in range(m):
    u,v,l,a = map(int,input().split())
    g[u].append((v,l,a))
    edges.append((u,v))

ok = [0]*n
ok[0] = 1
q = [0]
while q:
    u = q.pop()
    for v,l,a in g[u]:
        if ok[v]==0:
            ok[v] = 1
            q.append(v)

if ok[-1]==0:
    print(0)
    exit()

ind = [0]*n
for u,v in edges:
    if ok[u]:
        ind[v] += 1

MOD = 10**9+7
q = [i for i in range(n) if ok[i] and ind[i]==0]
dpnum = [0]*n
dpval = [0]*n
dpnum[0] = 1
while q:
    u = q.pop()
    for v,l,a in g[u]:
        dpnum[v] += a*dpnum[u]
        dpnum[v] %= MOD
        dpval[v] += (dpval[u] + dpnum[u]*l)%MOD*a
        dpval[v] %= MOD
        ind[v] -= 1
        if ind[v]==0: q.append(v)

if sum(ind):
    print("INF")
else:
    print(dpval[-1])
0