#abc239g. G - Builder Takahashi

G - Builder Takahashi

Score : 600600 points

问题描述

我们有一个简单的连通无向图,包含 NN 个顶点和 MM 条边。
顶点按照 Vertex 11, Vertex 22, \dots, Vertex NN 编号。
边按照 Edge 11, Edge 22, \dots, Edge MM 编号。其中边 ii 双向连接顶点 aia_i 和顶点 bib_i。不存在直接连接顶点 11 和顶点 NN 的边。
每个顶点要么为空,要么被墙占据。最初,所有顶点都是空的。

Aoki 将沿图中的边从 Vertex 11 出发前往 Vertex NN。但是,他不允许移动到被墙占据的顶点上。

Takahashi 决定选择一些顶点建造墙壁,以确保无论 Aoki 选择哪条路径都无法到达 Vertex NN
在顶点 ii 上建造一面墙需要 Takahashi 支付 cic_i 日元(日本货币)。他不能在顶点 11 和顶点 NN 上建造墙壁

请问为了满足条件,Takahashi 需要花费多少日元来建造墙壁?同时,请输出实现最小成本的建墙方式。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a simple connected undirected graph with NN vertices and MM edges.
The vertices are numbered as Vertex 11, Vertex 22, \dots, Vertex NN.
The edges are numbered as Edge 11, Edge 22, \dots, Edge MM. Edge ii connects Vertex aia_i and Vertex bib_i bidirectionally. There is no edge that directly connects Vertex 11 and Vertex NN.
Each vertex is either empty or occupied by a wall. Initially, every vertex is empty.

Aoki is going to travel from Vertex 11 to Vertex NN along the edges on the graph. However, Aoki is not allowed to move to a vertex occupied by a wall.

Takahashi has decided to choose some of the vertices to build walls on, so that Aoki cannot travel to Vertex NN no matter which route he takes.
Building a wall on Vertex ii costs Takahashi cic_i yen (the currency of Japan). He cannot build a wall on Vertex 11 and Vertex NN.

How many yens is required for Takahashi to build walls so that the conditions is satisfied? Also, print the way of building walls to achieve the minimum cost.

Constraints

  • 3N1003 \leq N \leq 100
  • N1MN(N1)21N - 1 \leq M \leq \frac{N(N-1)}{2} - 1
  • 1ai<biN1 \leq a_i \lt b_i \leq N (1iM)(1 \leq i \leq M)
  • (ai,bi)(1,N)(a_i, b_i) \neq (1, N)
  • The given graph is simple and connected.
  • 1ci1091 \leq c_{i} \leq 10^9 (2iN1)(2 \leq i \leq N-1)
  • c1=cN=0c_1 = c_N = 0
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aMa_M bMb_M

c1c_1 c2c_2 \dots cNc_N

Output

Print in the following format. Here, C,kC,k, and pip_i are defined as follows.

  • CC is the cost that Takahashi will pay

  • kk is the number of vertices for Takahashi to build walls on

  • (p1,p2,,pk)(p_1,p_2,\dots,p_k) is a sequence of vertices on which Takahashi will build walls

CC

kk

p1p_1 p2p_2 \dots pkp_k

If there are multiple ways to build walls to satisfy the conditions with the minimum cost, print any of them.

Sample Input 1

5 5
1 2
2 3
3 5
2 4
4 5
0 8 3 4 0

Sample Output 1

7
2
3 4

If Takahashi builds walls on Vertex 33 and Vertex 44, paying 3+4=73 + 4 = 7 yen, Aoki is unable to travel from Vertex 11 to Vertex 55.
There is no way to satisfy the condition with less cost, so 77 yen is the answer.

Sample Input 2

3 2
1 2
2 3
0 1 0

Sample Output 2

1
1
2

Sample Input 3

5 9
1 2
1 3
1 4
2 3
2 4
2 5
3 4
3 5
4 5
0 1000000000 1000000000 1000000000 0

Sample Output 3

3000000000
3
2 3 4

update @ 2024/3/10 10:19:55