結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,384 KB
testcase_01 AC 73 ms
71,288 KB
testcase_02 AC 71 ms
71,232 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 175 ms
93,884 KB
testcase_24 AC 132 ms
88,564 KB
testcase_25 AC 264 ms
108,212 KB
testcase_26 AC 361 ms
121,808 KB
testcase_27 AC 282 ms
112,028 KB
testcase_28 AC 215 ms
99,568 KB
testcase_29 AC 270 ms
111,120 KB
testcase_30 AC 219 ms
99,488 KB
testcase_31 AC 182 ms
93,028 KB
testcase_32 AC 232 ms
109,148 KB
testcase_33 AC 359 ms
122,364 KB
testcase_34 AC 366 ms
119,140 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 215 ms
106,972 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 196 ms
119,008 KB
testcase_44 AC 198 ms
115,868 KB
testcase_45 AC 170 ms
110,864 KB
testcase_46 AC 97 ms
92,984 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

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