codeforces-scrape

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

225A.md (2272B)


      1 Source: https://codeforces.com/problemset/problem/225/A
      2 
      3 A. Dice Tower
      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 A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
     22 
     23  ![](https://espresso.codeforces.com/aaad913af3c7c48c97f89ca39b3028b521d1b181.png) 
     24 
     25 Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).
     26 
     27 Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.
     28 
     29 Input
     30 
     31 The first line contains a single integer *n* (1 ≤ *n* ≤ 100) — the number of dice in the tower.
     32 
     33 The second line contains an integer *x* (1 ≤ *x* ≤ 6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*, *b**i* (1 ≤ *a**i*, *b**i* ≤ 6; *a**i* ≠ *b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower.
     34 
     35 Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input.
     36 
     37 Output
     38 
     39 Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes).
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 3  
     47 6  
     48 3 2  
     49 5 4  
     50 2 4
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 YES
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 3  
     63 3  
     64 2 6  
     65 4 1  
     66 5 3
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 NO
     73 ```