結果
| 問題 |
No.2630 Colorful Vertices and Cheapest Paths
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-16 23:39:41 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 955 bytes |
| コンパイル時間 | 86 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 19,492 KB |
| 最終ジャッジ日時 | 2024-09-28 22:41:47 |
| 合計ジャッジ時間 | 7,601 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 21 |
ソースコード
n,m=map(int,input().split())
G=[[] for i in range(n)]
E=[(int(a)-1,int(b)-1) for a,b in (input().split() for i in range(m))]
for a,b in E:
G[a].append(b)
G[b].append(a)
C=[int(_)-1 for _ in input().split()]
W=[int(_) for _ in input().split()]
def func(start,goal):
import heapq
from math import inf
dist=[inf]*n
dist[start]=W[C[start]]
Q=[]
heapq.heappush(Q,(dist[start],start,[i==C[start] for i in range(10)]))
while Q:
d,v,visited=heapq.heappop(Q)
if v==goal:
return dist[v]
if d>dist[v]:
continue
for u in G[v]:
d2=dist[v]+(0 if visited[C[u]] else W[C[u]])
if d2<dist[u]:
dist[u]=d2
heapq.heappush(Q,(dist[u],u,[True if i==C[u] else visited[i] for i in range(10)]))
return -1
print(*list(map(lambda v:func(*v),[tuple(map(lambda x:int(x)-1,input().split())) for q in range(int(input()))])),sep='\n')