結果
| 問題 |
No.2630 Colorful Vertices and Cheapest Paths
|
| コンテスト | |
| ユーザー |
Koi
|
| 提出日時 | 2024-02-16 22:32:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,158 bytes |
| コンパイル時間 | 320 ms |
| コンパイル使用メモリ | 82,556 KB |
| 実行使用メモリ | 160,216 KB |
| 最終ジャッジ日時 | 2024-09-28 21:08:38 |
| 合計ジャッジ時間 | 19,036 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 TLE * 8 -- * 8 |
ソースコード
from collections import deque
N,M=map(int,input().split())
G=[[] for _ in range(N)]
for i in range(M):
a,b=map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
C=list(map(int,input().split()))
W=list(map(int,input().split()))
Group=[[-1]*N for _ in range(2**10)]
cost=[0]*(2**10)
for i in range(1,2**10):
T=0
w=0
S=set()
c=0
for j in range(10):
if((i>>j)&1):
S.add(j+1)
c+=W[j]
cost[i]=c
# que=deque([0])
# Group[i][0]=w
while T<N:
que=deque([T])
Group[i][T]=w
while len(que):
p=que.popleft()
for q in G[p]:
if(C[p] in S and C[q] in S and Group[i][q]==-1):
Group[i][q]=Group[i][p]
que.append(q)
while T<N and Group[i][T]!=-1:
T+=1
w+=1
Q=int(input())
answers=[]
for _ in range(Q):
ans=-1
u,v=map(int,input().split())
u-=1
v-=1
for j in range(1,2**10):
if(Group[j][u]==Group[j][v]):
if(ans==-1 or cost[j]<ans):
ans=cost[j]
answers.append(ans)
for ans in answers:
print(ans)
Koi