#P2932. Farm Earthquake
Farm Earthquake
Farm Earthquake
The farm is modeled as a set of \(P\) pastures (numbered \(1\ldots P\)) connected by \(C\) non‐directional cowpaths. An earthquake has damaged some of the pastures making them unpassable, although none of the cowpaths were damaged. The barn is located at pasture \(1\).
A total of \(N\) cows (each located in a different pasture) report an integer \(report_j\) (with \(2 \le report_j \le P\)) indicating that pasture \(report_j\) is undamaged but that the cow cannot return to the barn because every path from \(report_j\) to the barn passes through at least one damaged pasture.
Your task is to choose which pastures are damaged (other than the reported ones, which are guaranteed undamaged but unreachable) in order to maximize the number of pastures reachable from the barn. In other words, among all valid assignments of damaged/undamaged statuses that respect the reports, the unreachable set (which comprises both damaged and undamaged but isolated pastures) is minimized. Equivalently, if we let \(R\) be the set of pastures reachable from the barn using only undamaged pastures and avoiding any reported pasture (since reports force the pasture to remain unreachable), then you need to output the value of \(P - |R|\).
Hint: Consider removing all the reported pastures from the graph and finding the size of the connected component (in the remaining graph) that contains the barn (pasture 1). The answer is \(P\) minus this size.
inputFormat
The first line contains three integers \(P\), \(C\) and \(N\) (\(1 \le P \le 30000\), \(1 \le C \le 100000\), \(1 \le N \le P\)).
Each of the next \(C\) lines contains two integers \(a_i\) and \(b_i\) (\(1 \le a_i, b_i \le P\)), representing a bidirectional cowpath between pastures \(a_i\) and \(b_i\). Note that a cowpath might connect a pasture to itself or may appear multiple times.
The following \(N\) lines each contain a single integer \(report_j\) (with \(2 \le report_j \le P\)); each \(report_j\) indicates that pasture \(report_j\) is undamaged (as confirmed by a calling cow) but cannot reach the barn.
outputFormat
Output a single integer representing the minimum number of pastures from which it is not possible to return to the barn.
sample
5 5 1
1 2
2 3
3 4
2 5
4 5
3
1