結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | H3PO4 |
提出日時 | 2021-01-22 22:51:44 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,586 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 178,104 KB |
最終ジャッジ日時 | 2024-06-08 16:57:30 |
合計ジャッジ時間 | 85,922 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,382 ms
56,416 KB |
testcase_01 | AC | 899 ms
56,408 KB |
testcase_02 | AC | 894 ms
56,532 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 | 1,156 ms
73,564 KB |
testcase_24 | AC | 1,192 ms
72,152 KB |
testcase_25 | AC | 2,034 ms
131,240 KB |
testcase_26 | TLE | - |
testcase_27 | AC | 2,352 ms
148,728 KB |
testcase_28 | AC | 1,702 ms
111,452 KB |
testcase_29 | AC | 2,232 ms
147,200 KB |
testcase_30 | AC | 1,769 ms
115,192 KB |
testcase_31 | AC | 1,305 ms
87,632 KB |
testcase_32 | AC | 1,966 ms
130,340 KB |
testcase_33 | TLE | - |
testcase_34 | AC | 2,462 ms
158,308 KB |
testcase_35 | AC | 1,859 ms
114,292 KB |
testcase_36 | AC | 1,800 ms
114,352 KB |
testcase_37 | AC | 1,769 ms
106,740 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 2,159 ms
149,556 KB |
testcase_44 | AC | 1,411 ms
87,236 KB |
testcase_45 | AC | 2,002 ms
149,832 KB |
testcase_46 | AC | 916 ms
56,792 KB |
testcase_47 | AC | 894 ms
56,708 KB |
ソースコード
import sys from collections import defaultdict, deque from scipy.sparse.csgraph import connected_components from scipy.sparse import csr_matrix input = sys.stdin.buffer.readline def topological_sort(N, edges): outs = defaultdict(list) ins = defaultdict(int) for v1, v2, in edges: outs[v1].append(v2) ins[v2] += 1 q = deque(v1 for v1 in range(N) if ins[v1] == 0) while q: v1 = q.popleft() yield v1 for v2 in outs[v1]: ins[v2] -= 1 if ins[v2] == 0: q.append(v2) MOD = 10 ** 9 + 7 N, M = map(int, input().split()) edges = [list(map(int, input().split())) for _ in range(M)] # 強連結成分分解により不要部分を削除 edges_set = set((u, v) for u, v, _, _ in edges) edges_set.add((N, 0)) frm, to = [], [] for u, v in edges_set: frm.append(u) to.append(v) matr = csr_matrix(([1] * len(frm), (frm, to)), shape=(N + 1, N + 1)) _, labels = connected_components(matr, connection='strong') l0 = labels[0] nodes = [i for i, x in enumerate(labels) if x == l0] # 座圧 comp = {x: i for i, x in enumerate(nodes)} N1 = len(comp) succ = [[] for _ in range(N1)] new_edges = set() for u, v, l, a in edges: if u in comp and v in comp: cu, cv = comp[u], comp[v] succ[cu].append((cv, l, a)) new_edges.add((cu, cv)) # トポソ ts = list(topological_sort(N1, new_edges)) if len(ts) != N1: print('INF');exit() dp = [0] * N1 for v in ts: cur = dp[v] for s, l, a in succ[v]: dp[s] += (cur + l) * a dp[s] %= MOD print(dp[ts[-1]])