問題一覧 > 通常問題

No.2630 Colorful Vertices and Cheapest Paths

レベル : / AI推定難易度 : 1350 / 実行時間制限 : 1ケース 2.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 105
作問者 : Nzt3 / テスター : noya2 tassei903
お気に入りにしたユーザー ProblemId : 10435 / 自分の提出
問題文最終更新日: 2024-02-15 23:22:24
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
traP 作問ハッカソンコンテスト 002(day1) (順位表) の他の問題:

Problem Statement

There is an undirected graph with $N$ vertices and $M$ edges. The $i$-th edge connects vertices $A_i$ and $B_i$ bidirectionally.

The vertices are colored, and the color of vertex $i$ is $C_i$. It is guaranteed that $1\le C_i\le 10$.

Initially, no vertex is passable.

By paying a cost of $W_i$, all vertices of color $i$ become passable.

Answer $Q$ independent queries. The $i$-th query is described using $u_i,v_i$ as follows.

  • Find the minimum possible total cost paid when paying costs so that a path connecting vertex $u_i$ and vertex $v_i$ exists. If no path exists no matter how much cost is paid, output -1.
    • All vertices on the path (including the endpoints) must be passable.

Constraints

  • $2 \le N \le 10^4$
  • $0 \le M \le 10^4$
  • $1 \le A_i ,B_i \le N$
  • $1 \le C_i \le 10$
  • $1 \le W_i \le 10^9 (1 \le i \le 10)$
  • $1 \le Q \le 10^4$
  • $1 \le u_i < v_i \le N$
  • All inputs are integers.

Input

$N$ $M$
$A_1$ $B_1$
$\vdots$
$A_M$ $B_M$
$C_1$ $\ldots$ $C_N$
$W_1$ $\ldots$ $W_{10}$
$Q$
$u_1$ $v_1$
$\vdots$
$u_Q$ $v_Q$

Output

Output $Q$ lines. The $i$-th line should contain the answer to the $i$-th query.

Print a newline after each query.

Sample

Sample 1
Input
4 4
1 2
2 3
3 4
4 1
1 1 2 3
1 2 3 4 5 6 7 8 9 10
3
1 2
1 3
1 4
Output
1
3
4

For the $1$st query, the path $1\rightarrow 2$ can be achieved by paying a cost of $1$ for color $1$. No path with a smaller cost exists.

For the $2$nd query, the path $1\rightarrow 2\rightarrow 3$ can be achieved by paying a total cost of $3$ for colors $1,2$. No path with a smaller cost exists.

Sample 2
Input
2 0
1 1
1 100 100 100 100 100 100 100 100 100
1
1 2
Output
-1
Sample 3
Input
5 5
1 2
2 3
2 3
3 4
4 5
1 4 5 9 10
1000000000 1 1 1000000000 1000000000 1 1 1 1000000000 1000000000
4
1 5
2 3
1 2
1 5
Output
5000000000
2000000000
2000000000
5000000000

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。