#graph702. Builder Takahashi
Builder Takahashi
Builder Takahashi
Problem Source
AtCoder Beginner Contest 239 G
Problem Description
You are given a connected undirected graph with vertices and edges. You may place an obstacle on some vertices (but not on vertex or vertex ). The cost of placing an obstacle on vertex is . You must make vertex and vertex disconnected. Find the minimum-cost way to do this.
Input Format
The first line contains two integers $n, m(3\leq n\leq 100, n - 1\leq m \leq \frac{n(n-1)}{2}-1)$.
The following lines each contain two numbers ; there are no multiple edges or self-loops, and vertices and are not directly connected.
The next line contains integers ; it is guaranteed that .
Output Format
The first line outputs one number: the minimum cost.
The next line outputs a number : the number of vertices where obstacles are placed. The following line contains numbers: the vertices where obstacles are placed.
Sample Input
5 5
1 2
2 3
3 5
2 4
4 5
0 8 3 4 0
Sample Output
7
2
3 4
Constraints
; ; .
Hint
- Disconnecting vertex 1 from vertex n by removing (obstacle-ing) vertices is exactly a minimum vertex cut (minimum s-t cut on vertices) between 1 and n. Split each vertex into an in- and out-node with capacity (vertices 1 and n have capacity ), and run max-flow / min-cut.