結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | MasKoaTS |
提出日時 | 2021-11-07 12:51:45 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 339 ms / 2,000 ms |
コード長 | 1,442 bytes |
コンパイル時間 | 314 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 19,652 KB |
最終ジャッジ日時 | 2024-05-01 17:32:51 |
合計ジャッジ時間 | 5,963 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
11,008 KB |
testcase_01 | AC | 40 ms
11,008 KB |
testcase_02 | AC | 27 ms
11,008 KB |
testcase_03 | AC | 27 ms
11,008 KB |
testcase_04 | AC | 26 ms
11,008 KB |
testcase_05 | AC | 27 ms
11,008 KB |
testcase_06 | AC | 29 ms
11,136 KB |
testcase_07 | AC | 28 ms
11,136 KB |
testcase_08 | AC | 29 ms
11,008 KB |
testcase_09 | AC | 44 ms
11,136 KB |
testcase_10 | AC | 33 ms
11,264 KB |
testcase_11 | AC | 40 ms
11,520 KB |
testcase_12 | AC | 58 ms
12,032 KB |
testcase_13 | AC | 53 ms
11,776 KB |
testcase_14 | AC | 89 ms
12,416 KB |
testcase_15 | AC | 33 ms
11,392 KB |
testcase_16 | AC | 43 ms
11,392 KB |
testcase_17 | AC | 42 ms
11,392 KB |
testcase_18 | AC | 41 ms
11,392 KB |
testcase_19 | AC | 41 ms
11,264 KB |
testcase_20 | AC | 129 ms
14,080 KB |
testcase_21 | AC | 53 ms
11,776 KB |
testcase_22 | AC | 200 ms
17,024 KB |
testcase_23 | AC | 129 ms
14,464 KB |
testcase_24 | AC | 215 ms
16,256 KB |
testcase_25 | AC | 210 ms
16,256 KB |
testcase_26 | AC | 283 ms
17,280 KB |
testcase_27 | AC | 325 ms
18,176 KB |
testcase_28 | AC | 339 ms
18,048 KB |
testcase_29 | AC | 330 ms
17,920 KB |
testcase_30 | AC | 327 ms
19,652 KB |
testcase_31 | AC | 307 ms
19,508 KB |
testcase_32 | AC | 76 ms
11,904 KB |
testcase_33 | AC | 33 ms
11,264 KB |
testcase_34 | AC | 30 ms
11,136 KB |
testcase_35 | AC | 61 ms
12,544 KB |
testcase_36 | AC | 50 ms
11,392 KB |
testcase_37 | AC | 48 ms
11,904 KB |
testcase_38 | AC | 114 ms
12,928 KB |
testcase_39 | AC | 57 ms
11,520 KB |
testcase_40 | AC | 59 ms
11,904 KB |
testcase_41 | AC | 165 ms
17,152 KB |
testcase_42 | AC | 99 ms
13,568 KB |
testcase_43 | AC | 65 ms
11,904 KB |
testcase_44 | AC | 117 ms
12,928 KB |
testcase_45 | AC | 43 ms
11,520 KB |
testcase_46 | AC | 200 ms
16,384 KB |
ソースコード
import itertools import heapq INF = float("inf") 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) if not(1 <= A+1 <= N and 1 <= B+1 <= N and 1 <= C <= 10**4): print((i,A+1,B+1,C)) exit(1) 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): 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)