Cable TV Network
Time limit5sMemory limit128 MB
Given an undirected graph, compute its vertex connectivity, the minimum number of vertices whose removal disconnects it (or n if never possible).
- Level
Medium6 of 10
- Topics
- Graph, Brute force, Math
- Solved
- No attempts yet
Problem
In a cable TV network the interconnection of the relays is bi-directional. The network is connected if there is at least one interconnection path between every pair of relays present in the network; otherwise it is disconnected. An empty network, or a network with a single relay, is considered connected.
The safety factor of a network with relays is defined as follows:
- , if the network stays connected no matter how many relays are removed from it.
- Otherwise, the minimum number of relays whose removal disconnects the network.

Figure 1. Cable TV networks
For example, consider the networks in Figure 1, where the circles mark the relays and the solid lines are interconnection cables. Network (a) stays connected regardless of how many relays are removed, so by rule (1) . Network (b) is already disconnected when relays are removed, hence by rule (2). Network (c) becomes disconnected when relays 1 and 2, or 1 and 3, are removed, so its safety factor is 2.
Write a program that reads several data sets and computes the safety factor of the cable network encoded by each data set.
Input
Each data set starts with two integers: the number of relays (), and the number of cables . Then follow data pairs with , where and are relay identifiers (integers in the range ). The pair designates the cable that interconnects relays and . The pairs may occur in any order. Except inside the pairs, which contain no white space, white space may occur freely in the input. The input terminates at end of file and is always correct.
Output
For each data set, print on standard output, starting at the beginning of a line, the safety factor of the encoded network.