結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー Nzt3Nzt3
提出日時 2024-02-12 00:27:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,121 ms / 2,500 ms
コード長 990 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 83,628 KB
最終ジャッジ日時 2024-02-12 00:27:57
合計ジャッジ時間 15,934 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 337 ms
77,188 KB
testcase_01 AC 753 ms
78,752 KB
testcase_02 AC 1,006 ms
81,152 KB
testcase_03 AC 68 ms
72,792 KB
testcase_04 AC 50 ms
64,436 KB
testcase_05 AC 69 ms
72,776 KB
testcase_06 AC 265 ms
77,744 KB
testcase_07 AC 937 ms
81,756 KB
testcase_08 AC 863 ms
80,976 KB
testcase_09 AC 942 ms
81,376 KB
testcase_10 AC 1,088 ms
81,036 KB
testcase_11 AC 1,121 ms
81,272 KB
testcase_12 AC 1,068 ms
81,232 KB
testcase_13 AC 1,044 ms
81,156 KB
testcase_14 AC 1,059 ms
81,296 KB
testcase_15 AC 492 ms
78,040 KB
testcase_16 AC 537 ms
78,040 KB
testcase_17 AC 473 ms
78,040 KB
testcase_18 AC 384 ms
78,332 KB
testcase_19 AC 619 ms
80,856 KB
testcase_20 AC 543 ms
79,712 KB
testcase_21 AC 717 ms
83,628 KB
権限があれば一括ダウンロードができます

ソースコード

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