Cable TV Network

Time limit5sMemory limit128 MB

Summary
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 ff of a network with nn relays is defined as follows:

  1. f=nf = n, if the network stays connected no matter how many relays are removed from it.
  2. 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) f=n=3f = n = 3. Network (b) is already disconnected when 00 relays are removed, hence f=0f = 0 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 nn (0≤n≤500 \le n \le 50), and the number of cables mm. Then follow mm data pairs (u,v)(u, v) with u<vu < v, where uu and vv are relay identifiers (integers in the range 0…n−10 \dots n-1). The pair (u,v)(u, v) designates the cable that interconnects relays uu and vv. The pairs may occur in any order. Except inside the (u,v)(u, v) 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.

Examples1

  1. Example 1

    Input
    0 0
    1 0
    3 3 (0,1) (0,2) (1,2)
    2 0
    5 7 (0,1) (0,2) (1,3) (1,2) (1,4) (2,3) (3,4)
    
    Expected output
    0
    1
    3
    0
    2