結果

問題 No.1814 Uribo Road (Easy)
ユーザー DrDrpilot
提出日時 2022-01-20 12:56:52
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 909 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-11-23 16:21:55
合計ジャッジ時間 68,114 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 TLE * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0