結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | neterukun |
提出日時 | 2021-01-22 22:18:16 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,037 bytes |
コンパイル時間 | 489 ms |
コンパイル使用メモリ | 82,028 KB |
実行使用メモリ | 174,080 KB |
最終ジャッジ日時 | 2024-12-28 02:11:30 |
合計ジャッジ時間 | 14,770 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 37 ms
52,632 KB |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | AC | 161 ms
90,564 KB |
testcase_24 | AC | 124 ms
83,132 KB |
testcase_25 | AC | 339 ms
132,004 KB |
testcase_26 | AC | 487 ms
174,080 KB |
testcase_27 | AC | 380 ms
146,964 KB |
testcase_28 | AC | 269 ms
126,504 KB |
testcase_29 | AC | 355 ms
142,428 KB |
testcase_30 | AC | 273 ms
129,124 KB |
testcase_31 | AC | 196 ms
100,768 KB |
testcase_32 | AC | 306 ms
136,516 KB |
testcase_33 | AC | 450 ms
153,052 KB |
testcase_34 | AC | 449 ms
152,820 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 268 ms
115,848 KB |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | AC | 290 ms
156,872 KB |
testcase_46 | WA | - |
testcase_47 | RE | - |
ソースコード
import sys input = sys.stdin.buffer.readline def topological_sorted(digraph): n = len(digraph) indegree = [0] * n for v in range(n): for nxt_v in digraph[v]: indegree[nxt_v] += 1 tp_order = [i for i in range(n) if indegree[i] == 0] stack = tp_order[:] while stack: v = stack.pop() for nxt_v in digraph[v]: indegree[nxt_v] -= 1 if indegree[nxt_v] == 0: stack.append(nxt_v) tp_order.append(nxt_v) return len(tp_order) == n, tp_order n, m = map(int, input().split()) edges = [list(map(int, input().split())) for i in range(m)] MOD = 10 ** 9 + 7 graph = [[] for i in range(n + 1)] for u, v, _, _ in edges: graph[u].append(v) rev_graph = [[] for i in range(n + 1)] for u, v, _, _ in edges: rev_graph[v].append(u) root = 0 reach = [False] * (n + 1) reach[0] = True stack = [root] while stack: v = stack.pop() for nxt_v in graph[v]: if reach[nxt_v]: continue reach[nxt_v] = True stack.append(nxt_v) root = n rev_reach = [False] * (n + 1) rev_reach[n] = True stack = [root] while stack: v = stack.pop() for nxt_v in rev_graph[v]: if rev_reach[nxt_v]: continue rev_reach[nxt_v] = True stack.append(nxt_v) if not reach[n]: print(-1) exit() for i in range(n + 1): reach[i] = reach[i] & rev_reach[i] graph = [set() for i in range(n + 1)] memo = {} for u, v, l, a in edges: if reach[u] and reach[v]: graph[u].add(v) if (u, v) not in memo: memo[u, v] = [] memo[u, v].append((l, a)) flag, tp_order = topological_sorted(graph) if not flag: print("INF") exit() print(re) ptn = [0] * (n + 1) ans = [0] * (n + 1) ptn[0] = 1 for v in tp_order: for nxt_v in graph[v]: for l, a in memo[v, nxt_v]: ptn[nxt_v] += ptn[v] * a ans[nxt_v] += l * a * ptn[v] ptn[nxt_v] %= MOD ans[nxt_v] %= MOD print(sum(ans) % MOD)