結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2021-11-06 15:36:01 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 399 ms / 2,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 19,508 KB |
最終ジャッジ日時 | 2024-11-21 22:59:37 |
合計ジャッジ時間 | 7,055 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
10,880 KB |
testcase_01 | AC | 44 ms
10,880 KB |
testcase_02 | AC | 31 ms
11,008 KB |
testcase_03 | AC | 32 ms
11,008 KB |
testcase_04 | AC | 31 ms
11,008 KB |
testcase_05 | AC | 32 ms
11,008 KB |
testcase_06 | AC | 34 ms
11,136 KB |
testcase_07 | AC | 32 ms
11,008 KB |
testcase_08 | AC | 31 ms
11,136 KB |
testcase_09 | AC | 49 ms
11,136 KB |
testcase_10 | AC | 41 ms
11,136 KB |
testcase_11 | AC | 46 ms
11,520 KB |
testcase_12 | AC | 67 ms
11,904 KB |
testcase_13 | AC | 63 ms
11,648 KB |
testcase_14 | AC | 98 ms
12,160 KB |
testcase_15 | AC | 37 ms
11,392 KB |
testcase_16 | AC | 47 ms
11,264 KB |
testcase_17 | AC | 49 ms
11,392 KB |
testcase_18 | AC | 47 ms
11,392 KB |
testcase_19 | AC | 46 ms
11,392 KB |
testcase_20 | AC | 139 ms
14,080 KB |
testcase_21 | AC | 58 ms
11,904 KB |
testcase_22 | AC | 232 ms
16,768 KB |
testcase_23 | AC | 156 ms
14,464 KB |
testcase_24 | AC | 257 ms
16,256 KB |
testcase_25 | AC | 252 ms
16,256 KB |
testcase_26 | AC | 327 ms
17,280 KB |
testcase_27 | AC | 383 ms
18,048 KB |
testcase_28 | AC | 393 ms
17,920 KB |
testcase_29 | AC | 399 ms
17,920 KB |
testcase_30 | AC | 397 ms
19,508 KB |
testcase_31 | AC | 369 ms
19,452 KB |
testcase_32 | AC | 83 ms
12,032 KB |
testcase_33 | AC | 37 ms
11,264 KB |
testcase_34 | AC | 35 ms
11,264 KB |
testcase_35 | AC | 67 ms
12,416 KB |
testcase_36 | AC | 58 ms
11,392 KB |
testcase_37 | AC | 61 ms
11,904 KB |
testcase_38 | AC | 121 ms
12,800 KB |
testcase_39 | AC | 64 ms
11,520 KB |
testcase_40 | AC | 69 ms
11,904 KB |
testcase_41 | AC | 182 ms
17,024 KB |
testcase_42 | AC | 104 ms
13,440 KB |
testcase_43 | AC | 71 ms
11,776 KB |
testcase_44 | AC | 129 ms
13,184 KB |
testcase_45 | AC | 50 ms
11,392 KB |
testcase_46 | AC | 240 ms
16,384 KB |
ソースコード
import itertools import heapq INF = 10 ** 9 N,M,K = map(int,input().split()) R = set([i-1 for i in map(int,input().split())]) lR = list(R) route = [[] for _ in [0]*N] edge = [0]*M st = set([0,N-1]) for i in range(M): A,B,C = map(int,input().split()) A -= 1; B -= 1 if(i in R): edge[i] = [A,B,C] st.add(A); st.add(B) route[A].append((B,C)) route[B].append((A,C)) def dijkstra(route): dist = [[-1]*N for _ in [0]*N] for i in st: q = [(0,i)] cnt = 0 while(q and cnt < N): d,v = heapq.heappop(q) if(dist[i][v] == -1): cnt += 1 dist[i][v] = d for nv,nd in route[v]: heapq.heappush(q,(d + nd,nv)) return dist ans = INF rsum = sum(edge[i][2] for i in R) dist = dijkstra(route) for rbit in range(1 << K): b = [(rbit >> i) & 1 for i in range(K)] dp = [[INF]*K for i in range(1 << K)] for i in range(K): p = edge[lR[i]][b[i]] dp[1 << i][i] = dist[0][p] + rsum for bit in range(1, 1 << K): if not(bit): continue for s in range(K): p = edge[lR[s]][b[s]^1] if not(bit & (1 << s)): continue for t in range(K): np = edge[lR[t]][b[t]] k = bit | (1 << t) d = dp[bit][s] + dist[p][np] if((bit & (1 << t)) == 0 and dp[k][t] > d): dp[k][t] = d c = INF for i in range(K): p = edge[lR[i]][b[i]^1] d = dp[-1][i] + dist[p][N-1] if(c > d): c = d if(ans > c): ans = c print(ans)