結果
問題 | No.1812 Uribo Road |
ユーザー | MasKoaTS |
提出日時 | 2021-12-30 22:31:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,432 ms / 5,000 ms |
コード長 | 1,467 bytes |
コンパイル時間 | 271 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 174,824 KB |
最終ジャッジ日時 | 2024-10-07 00:50:43 |
合計ジャッジ時間 | 14,430 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,864 KB |
testcase_01 | AC | 44 ms
52,608 KB |
testcase_02 | AC | 55 ms
63,872 KB |
testcase_03 | AC | 165 ms
80,896 KB |
testcase_04 | AC | 40 ms
52,352 KB |
testcase_05 | AC | 41 ms
52,992 KB |
testcase_06 | AC | 46 ms
53,376 KB |
testcase_07 | AC | 80 ms
73,472 KB |
testcase_08 | AC | 142 ms
76,980 KB |
testcase_09 | AC | 194 ms
79,264 KB |
testcase_10 | AC | 137 ms
77,240 KB |
testcase_11 | AC | 172 ms
77,776 KB |
testcase_12 | AC | 704 ms
147,876 KB |
testcase_13 | AC | 467 ms
133,200 KB |
testcase_14 | AC | 450 ms
132,964 KB |
testcase_15 | AC | 572 ms
109,916 KB |
testcase_16 | AC | 461 ms
121,992 KB |
testcase_17 | AC | 884 ms
150,660 KB |
testcase_18 | AC | 507 ms
115,072 KB |
testcase_19 | AC | 1,432 ms
171,428 KB |
testcase_20 | AC | 1,306 ms
173,008 KB |
testcase_21 | AC | 1,209 ms
172,156 KB |
testcase_22 | AC | 1,296 ms
174,824 KB |
testcase_23 | AC | 171 ms
78,396 KB |
testcase_24 | AC | 60 ms
63,360 KB |
testcase_25 | AC | 202 ms
82,172 KB |
testcase_26 | AC | 134 ms
77,056 KB |
testcase_27 | AC | 390 ms
105,728 KB |
testcase_28 | AC | 289 ms
87,792 KB |
testcase_29 | AC | 41 ms
52,864 KB |
testcase_30 | AC | 182 ms
79,104 KB |
testcase_31 | AC | 728 ms
121,476 KB |
testcase_32 | AC | 131 ms
77,568 KB |
testcase_33 | AC | 462 ms
103,032 KB |
ソースコード
import heapq import sys input = sys.stdin.readline INF = 10 ** 18 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 = {} for i in st: q = [(0,i)] st2 = set([]) while(q and len(st2) < len(st)): d,v = heapq.heappop(q) if((i,v) not in dist): if(v in st): st2.add(v) 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) 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[lR[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): d = dp[bit][s][i ^ 1] + dist[(edge[lR[s]][i],edge[lR[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[lR[i]][j],N - 1)] if(ans > d): ans = d print(ans)