結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | tktk_snsn |
提出日時 | 2021-01-22 21:57:43 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 973 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 87,012 KB |
実行使用メモリ | 689,624 KB |
最終ジャッジ日時 | 2023-08-27 18:53:36 |
合計ジャッジ時間 | 9,970 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | AC | 89 ms
71,724 KB |
testcase_02 | AC | 90 ms
71,264 KB |
testcase_03 | AC | 90 ms
71,760 KB |
testcase_04 | AC | 132 ms
77,664 KB |
testcase_05 | AC | 89 ms
71,624 KB |
testcase_06 | AC | 88 ms
71,628 KB |
testcase_07 | AC | 103 ms
77,600 KB |
testcase_08 | AC | 164 ms
83,228 KB |
testcase_09 | AC | 1,625 ms
273,756 KB |
testcase_10 | AC | 301 ms
109,600 KB |
testcase_11 | AC | 153 ms
82,408 KB |
testcase_12 | AC | 389 ms
135,792 KB |
testcase_13 | AC | 538 ms
153,592 KB |
testcase_14 | MLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
ソースコード
from collections import defaultdict 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() dp = [defaultdict(int) for _ in range(N + 1)] dp[N][0] += 1 # len, cnt for s in topo[::-1][:-1]: for k, v in dp[s].items(): for t, dist, num in back[s]: dp[t][k + dist] += v * num % mod dp[t][k + dist] %= mod ans = 0 for k, v in dp[0].items(): ans += k * v ans %= mod print(ans)