結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-22 22:15:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 903 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 149,144 KB
最終ジャッジ日時 2023-08-27 19:40:35
合計ジャッジ時間 17,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,200 KB
testcase_01 AC 73 ms
70,896 KB
testcase_02 AC 72 ms
70,896 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 184 ms
93,580 KB
testcase_24 AC 138 ms
88,780 KB
testcase_25 AC 275 ms
108,196 KB
testcase_26 AC 381 ms
121,552 KB
testcase_27 AC 290 ms
111,484 KB
testcase_28 AC 220 ms
99,284 KB
testcase_29 AC 278 ms
111,008 KB
testcase_30 AC 226 ms
99,264 KB
testcase_31 AC 189 ms
93,112 KB
testcase_32 AC 240 ms
109,012 KB
testcase_33 AC 379 ms
122,344 KB
testcase_34 AC 369 ms
118,940 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 218 ms
106,800 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 196 ms
119,016 KB
testcase_44 AC 200 ms
115,692 KB
testcase_45 AC 170 ms
110,944 KB
testcase_46 AC 97 ms
92,632 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10**9+7

N, M = map(int, input().split())
deg = [0] * (N+1)
go = [[] for _ in range(N+1)]
back = [[] for _ in range(N+1)]
for _ in range(M):
    a, b, c, d = map(int, input().split())
    go[a].append((b, c, d))
    back[b].append((a, c, d))
    deg[b] += 1

topo = []
q = []
for i, d in enumerate(deg):
    if d == 0:
        q.append(i)
while q:
    s = q.pop()
    topo.append(s)
    for t, _, _ in go[s]:
        deg[t] -= 1
        if deg[t] == 0:
            q.append(t)

if len(topo) < N + 1:
    print("INF")
    exit()


cnt = [0] * (N + 1)
cnt[N] = 1
for s in topo[::-1]:
    for t, _, num in back[s]:
        cnt[t] += num * cnt[s]
        cnt[t] %= mod


if cnt[0] == 0:
    print(0)
    exit()


ans = 0
for s in topo:
    for t, d, num in go[s]:
        ans += d * num * cnt[t]
        ans %= mod
print(ans)
0