eolymp
bolt
Try our new interface for solving problems
Məsələlər

Safety Grade

Safety Grade

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 Sof the network is defined as follows. \begin{itemize} \item \textbf{S} is \textbf{0} if the network is disconnected, or the number of sites is \textbf{0} or \textbf{1}. \item If the number of sites is greater than \textbf{1} then \textbf{S} is the minimum number of cables that disconnect the network when removed, i.e. removing any \textbf{S-1} cables keeps the net connected, while the removal of some \textbf{S} cables disconnects the net. \end{itemize} \includegraphics{https://static.e-olymp.com/content/06/068e14b2cc5cce90bdc9a36c3b07a7611a31d04f.jpg} For example, consider the net in figure \textbf{1}, where the sites correspond to the shadowed circles and the cables are indicated by lines. The network stays connected when removing any single cable, whereas the removal of cables (\textbf{0}, \textbf{2}), and (\textbf{1}, \textbf{3}) disconnects the net. Another variant for disconnecting the net is by removing the cables (\textbf{2}, \textbf{4}) and (\textbf{2}, \textbf{4}). The safety grade is \textbf{S=2}. Write a program that reads several data sets from a text file and computes the safety grade of the cable networks the data sets encode. \InputFile Each data set starts with two integers: the number \textbf{0} ≤ \textbf{n} ≤ \textbf{100} of sites in the net, and \textbf{0} ≤ \textbf{m} ≤ \textbf{1000} the number of cables in the net. Follow \textbf{m} data pairs (\textbf{u}, \textbf{v}), \textbf{u} < \textbf{v}, where \textbf{u} and \textbf{v} are site identifiers (integers from \textbf{0} to \textbf{n-1}). A pair (\textbf{u}, \textbf{v}) designates a cable that interconnects the sites \textbf{u} and \textbf{v}. The pairs may occur in any order. Except the (\textbf{u}, \textbf{v}) pairs, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and are correct. \OutputFile For each data set, the program prints on the standard output, from the beginning of a line, the safety grade of the encoded net.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
0 0
2 1 (0,1)
2 0
5 8 (0,1) (1,3) (2,3) (0,2) (0,1) (2,3) (2,4) (2,4)
Çıxış verilənləri #1
0
1
0
2

Şərh: The first data set encodes an empty network. The second data set encodes a net with 2 sites and 1 cable. The third data set corresponds to a disconnected network with two sites. The fourth data set encodes the net shown in figure 1.

Mənbə SEERC-2011