結果
問題 | No.1814 Uribo Road (Easy) |
ユーザー | 👑 SPD_9X2 |
提出日時 | 2022-01-16 16:52:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 181 ms / 2,000 ms |
コード長 | 2,452 bytes |
コンパイル時間 | 614 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 82,212 KB |
最終ジャッジ日時 | 2024-05-02 18:24:20 |
合計ジャッジ時間 | 7,149 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,120 KB |
testcase_01 | AC | 42 ms
53,888 KB |
testcase_02 | AC | 40 ms
53,120 KB |
testcase_03 | AC | 39 ms
52,992 KB |
testcase_04 | AC | 40 ms
52,864 KB |
testcase_05 | AC | 38 ms
53,248 KB |
testcase_06 | AC | 38 ms
53,376 KB |
testcase_07 | AC | 38 ms
52,864 KB |
testcase_08 | AC | 38 ms
52,992 KB |
testcase_09 | AC | 73 ms
70,912 KB |
testcase_10 | AC | 70 ms
70,784 KB |
testcase_11 | AC | 73 ms
71,808 KB |
testcase_12 | AC | 108 ms
77,824 KB |
testcase_13 | AC | 103 ms
77,160 KB |
testcase_14 | AC | 133 ms
78,208 KB |
testcase_15 | AC | 76 ms
73,856 KB |
testcase_16 | AC | 88 ms
76,800 KB |
testcase_17 | AC | 108 ms
76,672 KB |
testcase_18 | AC | 64 ms
68,224 KB |
testcase_19 | AC | 55 ms
63,744 KB |
testcase_20 | AC | 141 ms
78,976 KB |
testcase_21 | AC | 137 ms
77,592 KB |
testcase_22 | AC | 141 ms
80,128 KB |
testcase_23 | AC | 158 ms
78,848 KB |
testcase_24 | AC | 165 ms
80,484 KB |
testcase_25 | AC | 159 ms
80,468 KB |
testcase_26 | AC | 173 ms
81,440 KB |
testcase_27 | AC | 167 ms
82,212 KB |
testcase_28 | AC | 167 ms
82,180 KB |
testcase_29 | AC | 181 ms
82,096 KB |
testcase_30 | AC | 114 ms
80,512 KB |
testcase_31 | AC | 117 ms
80,384 KB |
testcase_32 | AC | 121 ms
77,952 KB |
testcase_33 | AC | 64 ms
67,328 KB |
testcase_34 | AC | 55 ms
63,104 KB |
testcase_35 | AC | 92 ms
77,440 KB |
testcase_36 | AC | 101 ms
76,800 KB |
testcase_37 | AC | 89 ms
77,312 KB |
testcase_38 | AC | 140 ms
78,464 KB |
testcase_39 | AC | 106 ms
77,184 KB |
testcase_40 | AC | 111 ms
77,568 KB |
testcase_41 | AC | 120 ms
80,128 KB |
testcase_42 | AC | 124 ms
78,592 KB |
testcase_43 | AC | 105 ms
77,184 KB |
testcase_44 | AC | 133 ms
78,848 KB |
testcase_45 | AC | 108 ms
77,184 KB |
testcase_46 | AC | 158 ms
80,128 KB |
ソースコード
""" bitdpっぽくやるのね… 10^7... 厳しめ dp[bit][最後][LorR] = mincost """ from sys import stdin import heapq def Dijkstra(lis,start): ret = [float("inf")] * len(lis) ret[start] = 0 q = [(0,start)] while len(q) > 0: ncost,now = heapq.heappop(q) if ncost != ret[now]: continue for nex,ecost in lis[now]: if ret[nex] > ncost + ecost: ret[nex] = ncost + ecost heapq.heappush(q , (ret[nex] , nex)) return ret N,M,K = map(int,stdin.readline().split()) R = list(map(int,stdin.readline().split())) for i in range(K): R[i] -= 1 lis = [ [] for i in range(N) ] ABC = [] for i in range(M): A,B,C = map(int,stdin.readline().split()) A -= 1 B -= 1 ABC.append( (A,B,C) ) lis[A].append( (B,C) ) lis[B].append( (A,C) ) ddic = {} ddic[0] = Dijkstra(lis,0) ddic[N-1] = Dijkstra(lis,N-1) for nr in R: l,r,_ = ABC[nr] if l not in ddic: ddic[l] = Dijkstra(lis,l) if r not in ddic: ddic[r] = Dijkstra(lis,r) #print (ddic) inf = float("inf") dp = [ [[inf,inf] for j in range(K)] for i in range(2**K) ] # dp[bit][最後][LorR] = mincost for i,nr in enumerate(R): l,r,c = ABC[nr] dp[2**i][i][0] = ddic[0][r] + c dp[2**i][i][1] = ddic[0][l] + c def popcnt(x): ret = 0 while x: ret += x%2 x //= 2 return ret for bit in range(2**K): for lastNR in range(K): for lastSide in range(2): lastL,lastR,_ = ABC[R[lastNR]] lastV = [lastL,lastR][lastSide] if dp[bit][lastNR][lastSide] == inf: continue for newNR in range(K): newbit = 2**newNR | bit if bit == newbit: continue newL,newR,newC = ABC[R[newNR]] dp[newbit][newNR][0] = min(dp[newbit][newNR][0] , dp[bit][lastNR][lastSide] + ddic[lastV][newR] + newC ) dp[newbit][newNR][1] = min(dp[newbit][newNR][1] , dp[bit][lastNR][lastSide] + ddic[lastV][newL] + newC ) ans = inf bit = 2**K-1 for lastNR in range(K): for lastSide in range(2): lastL,lastR,_ = ABC[R[lastNR]] lastV = [lastL,lastR][lastSide] ans = min(ans , dp[bit][lastNR][lastSide] + ddic[lastV][N-1]) print (ans)