結果
問題 | 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
|
実行時間 | 341 ms / 2,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 19,500 KB |
最終ジャッジ日時 | 2024-05-01 17:31:55 |
合計ジャッジ時間 | 6,172 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
11,008 KB |
testcase_01 | AC | 36 ms
11,008 KB |
testcase_02 | AC | 29 ms
11,008 KB |
testcase_03 | AC | 28 ms
11,008 KB |
testcase_04 | AC | 29 ms
11,008 KB |
testcase_05 | AC | 29 ms
11,136 KB |
testcase_06 | AC | 30 ms
11,008 KB |
testcase_07 | AC | 28 ms
11,008 KB |
testcase_08 | AC | 28 ms
11,008 KB |
testcase_09 | AC | 45 ms
11,264 KB |
testcase_10 | AC | 33 ms
11,136 KB |
testcase_11 | AC | 41 ms
11,520 KB |
testcase_12 | AC | 64 ms
11,904 KB |
testcase_13 | AC | 57 ms
11,648 KB |
testcase_14 | AC | 96 ms
12,160 KB |
testcase_15 | AC | 34 ms
11,264 KB |
testcase_16 | AC | 43 ms
11,392 KB |
testcase_17 | AC | 45 ms
11,392 KB |
testcase_18 | AC | 45 ms
11,392 KB |
testcase_19 | AC | 41 ms
11,264 KB |
testcase_20 | AC | 124 ms
14,080 KB |
testcase_21 | AC | 55 ms
11,648 KB |
testcase_22 | AC | 206 ms
16,896 KB |
testcase_23 | AC | 142 ms
14,592 KB |
testcase_24 | AC | 221 ms
16,256 KB |
testcase_25 | AC | 224 ms
16,256 KB |
testcase_26 | AC | 295 ms
17,280 KB |
testcase_27 | AC | 341 ms
18,048 KB |
testcase_28 | AC | 325 ms
17,920 KB |
testcase_29 | AC | 332 ms
17,920 KB |
testcase_30 | AC | 321 ms
19,500 KB |
testcase_31 | AC | 319 ms
19,492 KB |
testcase_32 | AC | 75 ms
12,032 KB |
testcase_33 | AC | 34 ms
11,264 KB |
testcase_34 | AC | 31 ms
11,136 KB |
testcase_35 | AC | 60 ms
12,416 KB |
testcase_36 | AC | 50 ms
11,392 KB |
testcase_37 | AC | 48 ms
11,904 KB |
testcase_38 | AC | 112 ms
12,800 KB |
testcase_39 | AC | 57 ms
11,520 KB |
testcase_40 | AC | 62 ms
11,904 KB |
testcase_41 | AC | 165 ms
17,152 KB |
testcase_42 | AC | 97 ms
13,568 KB |
testcase_43 | AC | 65 ms
11,648 KB |
testcase_44 | AC | 114 ms
13,056 KB |
testcase_45 | AC | 47 ms
11,520 KB |
testcase_46 | AC | 189 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)