codeforces-scrape

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

771A.md (2297B)


      1 Source: https://codeforces.com/problemset/problem/771/A
      2 
      3 A. Bear and Friendship Condition
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
     22 
     23 There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves.
     24 
     25 Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
     26 
     27 For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
     28 
     29 Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
     30 
     31 Input
     32 
     33 The first line of the input contain two integers *n* and *m* (3 ≤ *n* ≤ 150 000, ![](https://espresso.codeforces.com/b42f66704052fe39dd9de801c578ecf53d48d0fe.png)) — the number of members and the number of pairs of members that are friends.
     34 
     35 The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1 ≤ *a**i*, *b**i* ≤ *n*, *a**i* ≠ *b**i*). Members *a**i* and *b**i* are friends with each other. No pair of members will appear more than once in the input.
     36 
     37 Output
     38 
     39 If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 4 3  
     47 1 3  
     48 3 4  
     49 1 4
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 YES
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 4 4  
     62 3 1  
     63 2 3  
     64 3 4  
     65 1 2
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 NO
     72 ```
     73 
     74 Input
     75 
     76 ```
     77 10 4  
     78 4 3  
     79 5 10  
     80 8 9  
     81 1 2
     82 ```
     83 
     84 Output
     85 
     86 ```
     87 YES
     88 ```
     89 
     90 Input
     91 
     92 ```
     93 3 2  
     94 1 2  
     95 2 3
     96 ```
     97 
     98 Output
     99 
    100 ```
    101 NO
    102 ```
    103 
    104 Note
    105 
    106 The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
    107 
    108  ![](https://espresso.codeforces.com/999abd3a2ce8ac1986b5396a1ab1d24150213635.png)