結果

問題 No.1690 Power Grid
ユーザー とりゐとりゐ
提出日時 2021-09-24 22:07:54
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 823 ms / 3,000 ms
コード長 861 bytes
コンパイル時間 466 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 80,176 KB
最終ジャッジ日時 2023-09-18 21:26:35
合計ジャッジ時間 13,322 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,376 KB
testcase_01 AC 74 ms
71,052 KB
testcase_02 AC 114 ms
76,928 KB
testcase_03 AC 73 ms
71,424 KB
testcase_04 AC 72 ms
71,300 KB
testcase_05 AC 73 ms
71,076 KB
testcase_06 AC 534 ms
79,336 KB
testcase_07 AC 534 ms
79,684 KB
testcase_08 AC 535 ms
79,480 KB
testcase_09 AC 533 ms
79,724 KB
testcase_10 AC 620 ms
79,412 KB
testcase_11 AC 522 ms
79,876 KB
testcase_12 AC 72 ms
71,352 KB
testcase_13 AC 95 ms
76,860 KB
testcase_14 AC 174 ms
78,160 KB
testcase_15 AC 677 ms
79,588 KB
testcase_16 AC 823 ms
79,728 KB
testcase_17 AC 359 ms
78,972 KB
testcase_18 AC 248 ms
78,600 KB
testcase_19 AC 671 ms
79,836 KB
testcase_20 AC 688 ms
79,648 KB
testcase_21 AC 700 ms
79,428 KB
testcase_22 AC 663 ms
79,796 KB
testcase_23 AC 633 ms
79,564 KB
testcase_24 AC 697 ms
79,560 KB
testcase_25 AC 658 ms
80,176 KB
testcase_26 AC 669 ms
79,568 KB
testcase_27 AC 74 ms
71,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Warshall_Floyd(edges,N):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        edges[i][j]=min(edges[i][j],edges[i][k]+edges[k][j])
  return edges

INF=10**18
n,m,K=map(int,input().split())
a=list(map(int,input().split()))
edge=[[INF]*n for i in range(n)]
for i in range(m):
  x,y,k=map(int,input().split())
  x,y=x-1,y-1
  edge[x][y]=k
  edge[y][x]=k
for i in range(n):
  edge[i][i]=0
dist=Warshall_Floyd(edge,n)
dp=[INF]*(1<<n)
dp[0]=0
ans=INF
for bit in range(1<<n):
  if bit==0:
    for j in range(n):
      dp[1<<j]=a[j]
    continue
  if bin(bit).count('1')==K:
    ans=min(ans,dp[bit])
  x=[]
  y=[]
  for i in range(n):
    if bit&(1<<i)==0:
      x.append(i)
    else:
      y.append(i)
  for i in x:
    cost=INF
    for j in y:
      cost=min(cost,dist[i][j])
    dp[bit+2**i]=min(dp[bit+2**i],dp[bit]+cost+a[i])
print(ans)
0