Safety Grade
Time limit1sMemory limit128 MB
Given multigraphs with repeated edges, compute the global minimum edge cut (edge connectivity) or 0 if disconnected or trivial.
Problem
The sites of a cable network are interconnected by cables such that a cable connects a single pair of distinct sites, and a pair of sites can be connected by several cables. We say that the network is connected if any two sites in the network are directly or indirectly connected; otherwise the network is disconnected. The safety grade of the network is defined as follows.
- is if the network is disconnected, or the number of sites is or .
- If the number of sites is greater than , then is the minimum number of cables that disconnect the network when removed; that is, removing any cables keeps the network connected, while the removal of some cables disconnects it.
For example, consider a network on sites whose cables are (twice), , (twice), and (twice). The network stays connected when any single cable is removed, whereas removing cables and disconnects it; another way to disconnect it is to remove both copies of cable . Its safety grade is .
Write a program that reads several data sets and computes the safety grade of the cable networks the data sets encode.
Input
Each data set starts with two integers: the number of sites in the network, and the number of cables. Then follow data pairs , with , where and are site identifiers (integers from to ). A pair designates a cable that interconnects the sites and . The pairs may occur in any order. Except for the pairs, which do not contain white spaces, white spaces can occur freely in the input. The input terminates at end of file and is always correct.
Output
For each data set, print, from the beginning of a line, the safety grade of the encoded network.
Note
In the sample, the first data set encodes an empty network, the second a network with 2 sites and 1 cable, the third a disconnected network with two sites, and the fourth the five-site network described above.