結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,852 KB
testcase_01 WA -
testcase_02 AC 72 ms
70,676 KB
testcase_03 AC 85 ms
70,436 KB
testcase_04 AC 75 ms
70,764 KB
testcase_05 AC 73 ms
70,900 KB
testcase_06 AC 75 ms
70,412 KB
testcase_07 AC 76 ms
70,560 KB
testcase_08 AC 120 ms
78,128 KB
testcase_09 AC 119 ms
77,948 KB
testcase_10 AC 119 ms
77,852 KB
testcase_11 AC 113 ms
78,224 KB
testcase_12 AC 132 ms
77,760 KB
testcase_13 AC 283 ms
107,544 KB
testcase_14 AC 423 ms
117,756 KB
testcase_15 AC 359 ms
115,368 KB
testcase_16 AC 299 ms
103,828 KB
testcase_17 AC 175 ms
93,912 KB
testcase_18 AC 389 ms
123,332 KB
testcase_19 AC 388 ms
122,928 KB
testcase_20 AC 386 ms
123,456 KB
testcase_21 AC 393 ms
123,104 KB
testcase_22 AC 394 ms
123,128 KB
testcase_23 WA -
testcase_24 AC 171 ms
86,168 KB
testcase_25 AC 318 ms
100,940 KB
testcase_26 AC 439 ms
111,340 KB
testcase_27 AC 353 ms
105,216 KB
testcase_28 AC 242 ms
92,804 KB
testcase_29 AC 336 ms
105,096 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 281 ms
99,768 KB
testcase_33 AC 402 ms
110,668 KB
testcase_34 AC 395 ms
109,584 KB
testcase_35 AC 336 ms
110,956 KB
testcase_36 AC 327 ms
110,232 KB
testcase_37 AC 249 ms
99,600 KB
testcase_38 AC 325 ms
115,960 KB
testcase_39 AC 325 ms
115,960 KB
testcase_40 AC 328 ms
115,688 KB
testcase_41 AC 327 ms
116,112 KB
testcase_42 AC 322 ms
115,744 KB
testcase_43 AC 218 ms
101,348 KB
testcase_44 AC 214 ms
110,904 KB
testcase_45 WA -
testcase_46 AC 73 ms
76,240 KB
testcase_47 AC 71 ms
70,948 KB
権限があれば一括ダウンロードができます

ソースコード

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 dpnum[v]==0:
    print("INF")
else:
    print(dpval[-1])
0