結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2022-01-12 22:10:26 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,057 ms / 2,000 ms |
コード長 | 1,390 bytes |
コンパイル時間 | 461 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 20,384 KB |
最終ジャッジ日時 | 2024-05-01 17:33:21 |
合計ジャッジ時間 | 12,183 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,008 KB |
testcase_01 | AC | 32 ms
11,008 KB |
testcase_02 | AC | 31 ms
11,008 KB |
testcase_03 | AC | 32 ms
11,008 KB |
testcase_04 | AC | 31 ms
10,880 KB |
testcase_05 | AC | 32 ms
11,008 KB |
testcase_06 | AC | 31 ms
11,136 KB |
testcase_07 | AC | 31 ms
11,008 KB |
testcase_08 | AC | 31 ms
11,136 KB |
testcase_09 | AC | 44 ms
11,136 KB |
testcase_10 | AC | 39 ms
11,136 KB |
testcase_11 | AC | 51 ms
11,648 KB |
testcase_12 | AC | 95 ms
12,160 KB |
testcase_13 | AC | 86 ms
12,032 KB |
testcase_14 | AC | 147 ms
12,288 KB |
testcase_15 | AC | 36 ms
11,008 KB |
testcase_16 | AC | 37 ms
11,136 KB |
testcase_17 | AC | 37 ms
11,136 KB |
testcase_18 | AC | 36 ms
11,136 KB |
testcase_19 | AC | 35 ms
11,136 KB |
testcase_20 | AC | 242 ms
14,336 KB |
testcase_21 | AC | 68 ms
11,520 KB |
testcase_22 | AC | 443 ms
17,768 KB |
testcase_23 | AC | 266 ms
14,720 KB |
testcase_24 | AC | 529 ms
16,896 KB |
testcase_25 | AC | 519 ms
16,896 KB |
testcase_26 | AC | 684 ms
18,300 KB |
testcase_27 | AC | 871 ms
19,116 KB |
testcase_28 | AC | 868 ms
19,072 KB |
testcase_29 | AC | 879 ms
19,020 KB |
testcase_30 | AC | 1,057 ms
20,384 KB |
testcase_31 | AC | 941 ms
20,344 KB |
testcase_32 | AC | 114 ms
11,904 KB |
testcase_33 | AC | 42 ms
11,136 KB |
testcase_34 | AC | 38 ms
11,136 KB |
testcase_35 | AC | 88 ms
12,544 KB |
testcase_36 | AC | 58 ms
11,392 KB |
testcase_37 | AC | 65 ms
12,032 KB |
testcase_38 | AC | 204 ms
13,056 KB |
testcase_39 | AC | 72 ms
11,520 KB |
testcase_40 | AC | 100 ms
12,160 KB |
testcase_41 | AC | 301 ms
17,920 KB |
testcase_42 | AC | 174 ms
13,824 KB |
testcase_43 | AC | 85 ms
11,904 KB |
testcase_44 | AC | 224 ms
13,440 KB |
testcase_45 | AC | 62 ms
11,520 KB |
testcase_46 | AC | 441 ms
17,024 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] 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] 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] = dist[0][edge[R[i]][j ^ 1]] + edge[R[i]][2] for bit in range(1, 1 << K): for s in range(K): if not(bit & (1 << s)): continue for t in range(K): if(bit & (1 << t)): continue b = bit | (1 << t); c = edge[R[t]][2] for x in range(2): for y in range(2): p = edge[R[s]][x]; q = edge[R[t]][y ^ 1] d = dp[bit][s][x] + dist[p][q] + c if(dp[b][t][y] > d): dp[b][t][y] = d ans = INF for i in range(K): for j in range(2): d = dp[-1][i][j] + dist[edge[R[i]][j]][N - 1] if(ans > d): ans = d print(ans)