Earthquake Damage 2
Time limit1sMemory limit128 MB
Given an undirected graph and a set of vertices that cannot reach the barn, find the minimum number of other vertices to remove so that exactly those vertices are separated from vertex 1.
- Level
Hard8 of 10
- Topics
- Graph, BFS, Greedy, Implementation
- Solved
- No attempts yet
Problem
An earthquake has struck Farmer John's farm! The earthquake has damaged some of the pastures so that they are impassable. Remarkably, none of the cowpaths was damaged.
As usual, the farm is modeled as a set of () pastures numbered , connected by a set of () undirected cowpaths numbered . Cowpath connects pastures and (; ). A cowpath might connect a pasture to itself, and two pastures might be connected by more than one cowpath. The barn is located in pasture .
A total of () cows, each in a different pasture, sequentially contact Farmer John by phone. Cow sends an integer report () meaning that pasture is undamaged, but the calling cow cannot return to the barn from pasture because every path back to the barn passes through at least one damaged pasture.
After all cows have reported in, determine the minimum number of pastures that could be damaged. The barn (pasture ) and every reported pasture are guaranteed to be undamaged.
Input
- Line : Three space-separated integers: , , and .
- Lines : Line describes cowpath with two integers and .
- Lines : Line contains a single integer .
Output
- Line : One integer, the minimum number of damaged pastures.