output_description: Print the distance traveled by road if Joisino visits the towns in the order
  that minimizes it.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M R
      r_1 ... r_R
      A_1 B_1 C_1
      :
      A_M B_M C_M
attempt: #!/usr/bin/env python
  # ワーシャルフロイド+全探索
  
  import numpy as np
  import itertools
  
  def main():
      N, M, R = map(int, input().split())
      rs = [int(a)-1 for a in input().split())]
      inf = float('inf')
      cost = [[inf]*N for _ in range(N)]
  
      # グラフ作る
      for i in range(N):
          cost[i][i] = 0
  
      for _ in range(M):
          a, b, c = map(int, input().split())
          cost[a][b] = c
          cost[b][a] = c
      
      # ワーシャルフロイドで全頂点間距離算出
      for k in range(N):
          for i in range(N):
              for j in range(N):
                  if cost[i][k]+cost[k][j] < cost[i][j]:
                      cost[i][j] = cost[i][k] + cost[k][j]
  
      # 組み合わせ全探索
      ans = inf
      for route in itertools.permutations(rs):
          d = 0
          for i in range(R-1):
              d += cost[route[i]][route[i+1]]
              if d > ans:
                  break
          ans = min(ans, d)
      
      print(int(ans))
  
  
  if __name__=='__main__':
      main()
problem_description: Statement
  
  There are N towns in the State of Atcoder, connected by M bidirectional roads.
  
  The i-th road connects Town A_i and B_i and has a length of C_i.
  
  Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in
  this order).
  
  She will fly to the first town she visits, and fly back from the last town she
  visits, but for the rest of the trip she will have to travel by road.
  
  If she visits the towns in the order that minimizes the distance traveled by
  road, what will that distance be?
samples: [{"input": "3 3 3\n    1 2 3\n    1 2 1\n    2 3 1\n    3 1 4", "output": "2\n    \n\nFor example, if she visits the towns in the order of 1, 2, 3, the distance\ntraveled will be 2, which is the minimum possible.\n\n* * *"}, {"input": "3 3 2\n    1 3\n    2 3 2\n    1 3 6\n    1 2 2", "output": "4\n    \n\nThe shortest distance between Towns 1 and 3 is 4. Thus, whether she visits\nTown 1 or 3 first, the distance traveled will be 4.\n\n* * *"}, {"input": "4 6 3\n    2 3 4\n    1 2 4\n    2 3 3\n    4 3 1\n    1 4 1\n    4 2 2\n    3 1 6", "output": "3"}]