結果
問題 |
No.2630 Colorful Vertices and Cheapest Paths
|
ユーザー |
|
提出日時 | 2024-02-11 16:18:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,698 ms / 2,500 ms |
コード長 | 910 bytes |
コンパイル時間 | 353 ms |
コンパイル使用メモリ | 82,564 KB |
実行使用メモリ | 159,704 KB |
最終ジャッジ日時 | 2024-09-28 17:34:55 |
合計ジャッジ時間 | 23,499 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
N,M=map(int,input().split()) G=[[] for _ in range(N)] for _ in range(M): A,B=map(int,input().split()) A-=1 B-=1 G[A].append(B) G[B].append(A) C=list(map(lambda x:int(x)-1,input().split())) W=list(map(int,input().split())) root=[[-1]*N for _ in range(1<<10)] for i in range(1<<10): for j in range(N): if root[i][j]!=-1: continue root[i][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[i][k]==-1 and (i>>C[k]&1): root[i][k]=j q.append(k) 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(input()) for _ in range(Q): U,V=map(int,input().split()) U-=1 V-=1 ans=10**11 for i in range(1<<10): if root[i][U]==root[i][V]: ans=min(ans,cost[i]) if ans==10**11: ans=-1 print(ans)