In Graph City, there are
Thankfully, the city has recruited enough volunteers to help you move some of the existing pipes to new locations for free, however they are only willing to do this at most
Constraints
For this problem, you will NOT be required to pass all the samples in order to receive points. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.
Subtask | Points | |
---|---|---|
For all subtasks:
There will be at most one pipe directly connecting any two buildings.
Input Specification
The first line contains 3 integers,
The next
Output Specification
This problem is graded with an identical
checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n
character and that there are no trailing spaces.
Output a single integer, the minimum cost required to build new pipes to allow water to flow into all buildings, after moving at most
Sample Input 1
4 6 6
1 2
3 4
4 2
3 1
4 1
3 2
Sample Output 1
0
Sample Explanation 1
Since all buildings are connected to the water pump, no new pipes are built or moved.
Sample Input 2
4 1 0
2 3
Sample Output 2
2
Sample Explanation 2
We can build a pipe between buildings
Sample Input 3
6 4 1
1 2
2 3
3 1
4 5
Sample Output 3
1
Sample Explanation 3
We can move the existing pipe between buildings
Comments