atcoder#ABC239G. [ABC239G] Builder Takahashi
[ABC239G] Builder Takahashi
Score : points
Problem Statement
We have a simple connected undirected graph with vertices and edges. The vertices are numbered as Vertex , Vertex , , Vertex . The edges are numbered as Edge , Edge , , Edge . Edge connects Vertex and Vertex bidirectionally. There is no edge that directly connects Vertex and Vertex . Each vertex is either empty or occupied by a wall. Initially, every vertex is empty.
Aoki is going to travel from Vertex to Vertex 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 no matter which route he takes. Building a wall on Vertex costs Takahashi yen (the currency of Japan). He cannot build a wall on Vertex 1 and Vertex N.
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
- The given graph is simple and connected.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print in the following format. Here, , and are defined as follows.
- is the cost that Takahashi will pay
- is the number of vertices for Takahashi to build walls on
- is a sequence of vertices on which Takahashi will build walls
If there are multiple ways to build walls to satisfy the conditions with the minimum cost, print any of them.
5 5
1 2
2 3
3 5
2 4
4 5
0 8 3 4 0
7
2
3 4
If Takahashi builds walls on Vertex and Vertex , paying yen, Aoki is unable to travel from Vertex to Vertex . There is no way to satisfy the condition with less cost, so yen is the answer.
3 2
1 2
2 3
0 1 0
1
1
2
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
3000000000
3
2 3 4