結果
| 問題 |
No.1814 Uribo Road (Easy)
|
| ユーザー |
|
| 提出日時 | 2022-01-20 12:57:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 318 ms / 2,000 ms |
| コード長 | 909 bytes |
| コンパイル時間 | 833 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 78,064 KB |
| 最終ジャッジ日時 | 2024-11-23 16:22:48 |
| 合計ジャッジ時間 | 8,832 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
from itertools import permutations,product
n,m,k=map(int,input().split())
r=list(map(int,input().split()))
inf=float('inf')
d=[[inf]*n for _ in range(n)]
for i in range(n):
d[i][i]=0
path=[]
must_cost=0
for i in range(m):
a,b,c=map(int,input().split())
a-=1;b-=1
d[a][b]=c
d[b][a]=c
if i+1 in r:
path.append((a,b))
must_cost+=c
for z in range(n):
for i in range(n):
for j in range(n):
d[i][j]=min(d[i][j],d[i][z]+d[z][j])
ans=inf
for seq in permutations(range(k)):#通り順
for bit in product(range(2),repeat=k):
now=0
now_cost=must_cost
for i in range(k):
x,y=path[seq[i]]
if bit[i]==1:
now_cost+=d[now][x]
now=y
else:
now_cost+=d[now][y]
now=x
now_cost+=d[now][n-1]
ans=min(ans,now_cost)
print(ans)