codeforces-scrape

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

300B.md (2098B)


      1 Source: https://codeforces.com/problemset/problem/300/B
      2 
      3 B. Coach
      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 programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive.
     22 
     23 Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the *i*-th student wants to be on the same team with the *j*-th one, then the *j*-th student wants to be on the same team with the *i*-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the *i*-th student wants to be on the same team with the *j*-th, then the *i*-th and the *j*-th students must be on the same team. Also, it is obvious that each student must be on exactly one team.
     24 
     25 Help the coach and divide the teams the way he wants.
     26 
     27 Input
     28 
     29 The first line of the input contains integers *n* and *m* (3 ≤ *n* ≤ 48, ![](https://espresso.codeforces.com/babb38e387fa78be46ba7de9507b97ce0c3a0986.png). Then follow *m* lines, each contains a pair of integers *a**i*, *b**i* (1 ≤ *a**i* < *b**i* ≤ *n*) — the pair *a**i*, *b**i* means that students with numbers *a**i* and *b**i* want to be on the same team.
     30 
     31 It is guaranteed that *n* is divisible by 3. It is guaranteed that each pair *a**i*, *b**i* occurs in the input at most once.
     32 
     33 Output
     34 
     35 If the required division into teams doesn't exist, print number -1. Otherwise, print ![](https://espresso.codeforces.com/3fd2941ef9a7bdc91b7d0b8372f289e78e262c96.png) lines. In each line print three integers *x**i*, *y**i*, *z**i* (1 ≤ *x**i*, *y**i*, *z**i* ≤ *n*) — the *i*-th team.
     36 
     37 If there are multiple answers, you are allowed to print any of them.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 3 0
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 3 2 1
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 6 4  
     57 1 2  
     58 2 3  
     59 3 4  
     60 5 6
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 -1
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 3 3  
     73 1 2  
     74 2 3  
     75 1 3
     76 ```
     77 
     78 Output
     79 
     80 ```
     81 3 2 1
     82 ```