#P1345. Disconnecting Communication
Disconnecting Communication
Disconnecting Communication
Farmer John's cows have built a computer network so that they can exchange emails. Two computers can exchange emails if there exists a sequence of computers \(a_1,a_2,\cdots,a_c\) such that each consecutive pair is connected by a link. Unfortunately, sometimes a cow accidentally steps on a computer or the farmer's truck runs over one, causing it to fail. A failed computer can no longer send emails and all links connected to it become unavailable.
Given two designated computers \(c_1\) and \(c_2\) (which cannot be broken), determine the minimum number of other computers that must fail to disconnect \(c_1\) from \(c_2\); that is, so that there is no sequence of active computers connecting them.
Note: There exists a link between two computers if they are directly connected, and communication can flow along any path of linked computers.
For example, consider the network below:
1* / 3 - 2*
There are 3 computers and 2 links. The designated computers are 1 and 2 (marked with *). By failing computer 3, computers 1 and 2 become disconnected. Hence, the answer is 1.
inputFormat
The input starts with a line containing four integers \(n, m, c_1, c_2\) where \(n\) is the number of computers, \(m\) is the number of connections, and \(c_1\) and \(c_2\) are the labels of the two designated computers that cannot be failed. Computers are numbered from 1 to \(n\).
Each of the following \(m\) lines contains two integers \(u\) and \(v\) indicating that there is a direct bidirectional connection between computer \(u\) and computer \(v\>.
outputFormat
Output a single integer which is the minimum number of computers (other than \(c_1\) and \(c_2\)) that must fail in order to disconnect \(c_1\) from \(c_2\>.
sample
3 2 1 2
1 3
2 3
1