結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー 👑 timitimi
提出日時 2024-02-17 16:22:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 162,664 KB
最終ジャッジ日時 2024-02-17 16:23:02
合計ジャッジ時間 17,442 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 69 ms
73,444 KB
testcase_04 AC 45 ms
62,384 KB
testcase_05 AC 74 ms
73,440 KB
testcase_06 AC 745 ms
86,816 KB
testcase_07 AC 1,479 ms
158,568 KB
testcase_08 AC 1,402 ms
149,864 KB
testcase_09 AC 1,445 ms
159,208 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 804 ms
79,524 KB
testcase_16 AC 725 ms
79,028 KB
testcase_17 AC 767 ms
79,016 KB
testcase_18 AC 1,190 ms
100,120 KB
testcase_19 AC 1,422 ms
140,008 KB
testcase_20 AC 1,353 ms
127,848 KB
testcase_21 AC 1,546 ms
158,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int, input().split())
A=[]
for i in range(M):
  a,b=map(int, input().split())
  a-=1;b-=1
  A.append((a,b))
  
C=list(map(int, input().split()))
W=list(map(int, input().split()))
par=[i for i in range(N)]
rank=[0]*(N)
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
 
#同じ集合か判定
def same(x,y):
  return find(x)==find(y)
 
def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
  else:
    par[x]=y
    if rank[x]==rank[y]:
      rank[y]+=1
DD={}
for j in range(2**10):
  par=[i for i in range(N)]
  rank=[0]*(N)   
  D=[];s=0;now=j
  for k in range(10):
    D.append(j%2)
    s+=D[-1]*W[k]
    j//=2 
  for x,y in A:
    if D[C[x]-1]==1 and D[C[y]-1]==1:
      union(x,y)
  DD[now]=(par.copy(),s)

Q=int(input())
for _ in range(Q):
  ans=10**20
  a,b=map(int, input().split())
  for d in DD:
    P,s=DD[d]
    if P[a-1]==P[b-1]:
      ans=min(ans,s)
  if ans==10**20:
    print(-1)
  else:
    print(ans)
0