結果
問題 |
No.1364 [Renaming] Road to Cherry from Zelkova
|
ユーザー |
![]() |
提出日時 | 2021-01-22 22:09:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 860 bytes |
コンパイル時間 | 373 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 148,096 KB |
最終ジャッジ日時 | 2024-12-28 01:18:38 |
合計ジャッジ時間 | 15,627 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 28 |
ソースコード
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)