結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー Nzt3Nzt3
提出日時 2024-02-12 00:30:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 990 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 19,348 KB
最終ジャッジ日時 2024-02-12 00:30:43
合計ジャッジ時間 9,771 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
N,M=map(int,stdin.readline().split())
G=[[] for _ in range(N)]
for _ in range(M):
  A,B=map(int,stdin.readline().split())
  A-=1
  B-=1
  G[A].append(B)
  G[B].append(A)

C=list(map(lambda x:int(x)-1,stdin.readline().split()))
W=list(map(int,stdin.readline().split()))


cost=[0]*(1<<10)
for i in range(1<<10):
  for j in range(10):
    if i>>j&1:
      cost[i]+=W[j]

Q=int(stdin.readline())
Qs=[]
ans=[10**12]*Q
for i in range(Q):
  Qs.append(list(map(lambda x:int(x)-1,stdin.readline().split())))

for i in range(1<<10):
  root=[-1]*N
  for j in range(N):
    if root[j]!=-1:
      continue
    root[j]=j
    if (i>>C[j]&1)==0:
      continue
    q=[]
    l=0
    q.append(j)
    while len(q)>l:
      v=q[l]
      l+=1
      for k in G[v]:
        if root[k]==-1 and (i>>C[k]&1):
          root[k]=j
          q.append(k)
  for j in range(Q):
    if root[Qs[j][0]]==root[Qs[j][1]]:
      ans[j]=min(ans[j],cost[i])
for i in ans:
  if i==10**12:
    i=-1
  print(i)
0