codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

129B.md (2756B)


      1 Source: https://codeforces.com/problemset/problem/129/B
      2 
      3 B. Students and Shoelaces
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
     22 
     23 To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
     24 
     25 Determine how many groups of students will be kicked out of the club.
     26 
     27 Input
     28 
     29 The first line contains two integers *n* and *m* — the initial number of students and laces (![](https://espresso.codeforces.com/c0f4b517c1454fa53ac04e10a468e8c02ed79905.png)). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1 ≤ *a*, *b* ≤ *n*, *a* ≠ *b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
     30 
     31 Output
     32 
     33 Print the single number — the number of groups of students that will be kicked out from the club.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 3 3  
     41 1 2  
     42 2 3  
     43 3 1
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 0
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 6 3  
     56 1 2  
     57 2 3  
     58 3 4
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 2
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 6 5  
     71 1 4  
     72 2 4  
     73 3 4  
     74 5 4  
     75 6 4
     76 ```
     77 
     78 Output
     79 
     80 ```
     81 1
     82 ```
     83 
     84 Note
     85 
     86 In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
     87 
     88 In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
     89 
     90 In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.