結果
問題 | No.1812 Uribo Road |
ユーザー | MasKoaTS |
提出日時 | 2021-12-30 22:36:58 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,711 ms / 5,000 ms |
コード長 | 1,467 bytes |
コンパイル時間 | 221 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 56,908 KB |
最終ジャッジ日時 | 2024-10-07 00:52:43 |
合計ジャッジ時間 | 23,724 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 30 ms
10,880 KB |
testcase_02 | AC | 30 ms
10,880 KB |
testcase_03 | AC | 608 ms
17,024 KB |
testcase_04 | AC | 29 ms
10,880 KB |
testcase_05 | AC | 29 ms
10,880 KB |
testcase_06 | AC | 28 ms
10,880 KB |
testcase_07 | AC | 66 ms
11,520 KB |
testcase_08 | AC | 60 ms
11,904 KB |
testcase_09 | AC | 74 ms
12,288 KB |
testcase_10 | AC | 59 ms
12,156 KB |
testcase_11 | AC | 51 ms
11,776 KB |
testcase_12 | AC | 1,421 ms
54,388 KB |
testcase_13 | AC | 1,065 ms
53,140 KB |
testcase_14 | AC | 985 ms
51,472 KB |
testcase_15 | AC | 653 ms
24,124 KB |
testcase_16 | AC | 626 ms
35,720 KB |
testcase_17 | AC | 1,559 ms
44,800 KB |
testcase_18 | AC | 1,053 ms
21,408 KB |
testcase_19 | AC | 2,711 ms
51,884 KB |
testcase_20 | AC | 2,475 ms
51,428 KB |
testcase_21 | AC | 2,379 ms
55,948 KB |
testcase_22 | AC | 2,711 ms
56,908 KB |
testcase_23 | AC | 148 ms
13,052 KB |
testcase_24 | AC | 30 ms
10,880 KB |
testcase_25 | AC | 173 ms
17,428 KB |
testcase_26 | AC | 45 ms
11,392 KB |
testcase_27 | AC | 645 ms
17,612 KB |
testcase_28 | AC | 269 ms
20,840 KB |
testcase_29 | AC | 28 ms
10,880 KB |
testcase_30 | AC | 93 ms
12,160 KB |
testcase_31 | AC | 1,366 ms
31,440 KB |
testcase_32 | AC | 73 ms
11,648 KB |
testcase_33 | AC | 963 ms
27,220 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)