結果
問題 | No.1308 ジャンプビーコン |
ユーザー | tamato |
提出日時 | 2020-12-05 01:11:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,094 ms / 4,000 ms |
コード長 | 1,534 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 198,168 KB |
最終ジャッジ日時 | 2024-09-15 09:39:30 |
合計ジャッジ時間 | 36,419 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
53,888 KB |
testcase_01 | AC | 42 ms
53,888 KB |
testcase_02 | AC | 43 ms
54,272 KB |
testcase_03 | AC | 49 ms
61,312 KB |
testcase_04 | AC | 51 ms
61,056 KB |
testcase_05 | AC | 50 ms
61,440 KB |
testcase_06 | AC | 50 ms
61,312 KB |
testcase_07 | AC | 49 ms
61,288 KB |
testcase_08 | AC | 90 ms
76,676 KB |
testcase_09 | AC | 97 ms
76,744 KB |
testcase_10 | AC | 87 ms
76,928 KB |
testcase_11 | AC | 91 ms
76,484 KB |
testcase_12 | AC | 92 ms
76,544 KB |
testcase_13 | AC | 164 ms
77,312 KB |
testcase_14 | AC | 162 ms
77,312 KB |
testcase_15 | AC | 179 ms
77,408 KB |
testcase_16 | AC | 183 ms
77,696 KB |
testcase_17 | AC | 168 ms
77,368 KB |
testcase_18 | AC | 2,094 ms
175,072 KB |
testcase_19 | AC | 1,978 ms
169,436 KB |
testcase_20 | AC | 1,939 ms
148,256 KB |
testcase_21 | AC | 1,963 ms
177,328 KB |
testcase_22 | AC | 2,016 ms
160,812 KB |
testcase_23 | AC | 42 ms
54,016 KB |
testcase_24 | AC | 86 ms
77,052 KB |
testcase_25 | AC | 87 ms
76,672 KB |
testcase_26 | AC | 1,488 ms
132,144 KB |
testcase_27 | AC | 1,484 ms
133,632 KB |
testcase_28 | AC | 1,463 ms
120,448 KB |
testcase_29 | AC | 1,817 ms
182,564 KB |
testcase_30 | AC | 1,817 ms
189,248 KB |
testcase_31 | AC | 1,606 ms
133,816 KB |
testcase_32 | AC | 1,455 ms
198,168 KB |
testcase_33 | AC | 1,802 ms
144,672 KB |
testcase_34 | AC | 1,526 ms
130,064 KB |
testcase_35 | AC | 1,573 ms
151,168 KB |
testcase_36 | AC | 1,563 ms
132,864 KB |
testcase_37 | AC | 1,252 ms
122,880 KB |
testcase_38 | AC | 1,841 ms
146,816 KB |
testcase_39 | AC | 1,937 ms
136,792 KB |
ソースコード
mod = 1000000007 eps = 10**-9 inf = 10**18 def main(): import sys from collections import deque input = sys.stdin.buffer.readline N, Q, C = map(int, input().split()) adj = [[] for _ in range(N+1)] for _ in range(N-1): a, b, c = map(int, input().split()) adj[a].append((b, c)) adj[b].append((a, c)) X = list(map(int, input().split())) dp = [inf] * (N+1) dp[X[0]] = 0 for i in range(Q-1): u0 = X[i] v0 = X[i+1] que = deque() que.append(v0) seen = [-1] * (N+1) seen[v0] = 0 par = [0] * (N+1) child = [[] for _ in range(N+1)] seq = [] while que: v = que.popleft() seq.append(v) for u, c in adj[v]: if seen[u] == -1: seen[u] = seen[v] + c par[u] = v child[v].append(u) que.append(u) seq.reverse() dp_new = [inf] * (N+1) dp_tree = [inf] * (N+1) for j in range(1, N+1): if dp[j] == inf: continue dp_new[j] = dp[j] + seen[u0] dp_tree[u0] = min(dp_tree[u0], dp[j] + seen[u0]) dp_tree[j] = min(dp_tree[j], dp[j] + C + seen[j]) for v in seq: for u in child[v]: dp_tree[v] = min(dp_tree[v], dp_tree[u]) dp_new[v] = min(dp_new[v], dp_tree[v]) dp = dp_new print(min(dp)) if __name__ == '__main__': main()