結果
問題 | No.1812 Uribo Road |
ユーザー | MasKoaTS |
提出日時 | 2021-12-30 00:02:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,073 ms / 5,000 ms |
コード長 | 1,382 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 81,848 KB |
実行使用メモリ | 117,888 KB |
最終ジャッジ日時 | 2024-10-07 00:50:06 |
合計ジャッジ時間 | 12,940 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,864 KB |
testcase_01 | AC | 39 ms
52,992 KB |
testcase_02 | AC | 53 ms
63,232 KB |
testcase_03 | AC | 132 ms
80,896 KB |
testcase_04 | AC | 39 ms
52,992 KB |
testcase_05 | AC | 38 ms
53,504 KB |
testcase_06 | AC | 40 ms
53,504 KB |
testcase_07 | AC | 73 ms
72,704 KB |
testcase_08 | AC | 133 ms
76,908 KB |
testcase_09 | AC | 150 ms
77,440 KB |
testcase_10 | AC | 123 ms
76,916 KB |
testcase_11 | AC | 130 ms
76,800 KB |
testcase_12 | AC | 453 ms
86,772 KB |
testcase_13 | AC | 237 ms
85,860 KB |
testcase_14 | AC | 239 ms
85,632 KB |
testcase_15 | AC | 666 ms
97,592 KB |
testcase_16 | AC | 358 ms
82,240 KB |
testcase_17 | AC | 870 ms
101,908 KB |
testcase_18 | AC | 885 ms
117,888 KB |
testcase_19 | AC | 1,043 ms
108,328 KB |
testcase_20 | AC | 1,073 ms
109,040 KB |
testcase_21 | AC | 981 ms
109,576 KB |
testcase_22 | AC | 981 ms
111,016 KB |
testcase_23 | AC | 167 ms
78,008 KB |
testcase_24 | AC | 68 ms
69,376 KB |
testcase_25 | AC | 238 ms
82,108 KB |
testcase_26 | AC | 143 ms
77,700 KB |
testcase_27 | AC | 724 ms
105,332 KB |
testcase_28 | AC | 308 ms
83,548 KB |
testcase_29 | AC | 40 ms
52,992 KB |
testcase_30 | AC | 210 ms
78,732 KB |
testcase_31 | AC | 638 ms
96,800 KB |
testcase_32 | AC | 136 ms
76,956 KB |
testcase_33 | AC | 344 ms
88,280 KB |
ソースコード
import heapq as hq import sys input = sys.stdin.readline INF = 10 ** 18 N,M,K = map(int, input().split()) R = [i - 1 for i in map(int, input().split())] S = set(R) edge = [[] for _ in [0] * M] route = [[] for _ in [0] * N] rsum = 0 for i in range(M): a,b,c = map(int, input().split()) a -= 1; b -= 1 route[a].append((b,c)) route[b].append((a,c)) if(i in S): edge[i] = [a,b,c] rsum += c def dijkstra(s,route): que = [(0,s)] dist = [INF] * N while(que): d,v = hq.heappop(que) if(dist[v] < INF): continue dist[v] = d for nv,nd in route[v]: hq.heappush(que,(d + nd, nv)) return dist dist = [[] for _ in [0] * N] T = set([0,N - 1]) for i in S: T.add(edge[i][0]) T.add(edge[i][1]) for i in T: dist[i] = dijkstra(i,route) dp = [[[INF] * 2 for _ in [0] * K] for _ in [0] * (1 << K)] for i in range(K): for j in range(2): dp[1 << i][i][j] = rsum + dist[0][edge[R[i]][j]] for bit in range(1, 1 << K): for s in range(K): if not(bit & (1 << s)): continue for i in range(2): for t in range(K): if not(bit & (1 << t)): b = bit | (1 << t) for j in range(2): p = edge[R[t]][j] d = dp[bit][s][i ^ 1] + dist[edge[R[s]][i]][edge[R[t]][j]] if(dp[b][t][j] > d): dp[b][t][j] = d ans = INF for i in range(K): for j in range(2): d = dp[-1][i][j ^ 1] + dist[edge[R[i]][j]][N - 1] if(ans > d): ans = d print(ans)