codeforces-scrape

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

357B.md (2415B)


      1 Source: https://codeforces.com/problemset/problem/357/B
      2 
      3 B. Flag Day
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
     22 
     23 * overall, there must be *m* dances;
     24 * exactly three people must take part in each dance;
     25 * each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
     26 
     27 The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
     28 
     29 You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.
     30 
     31 Input
     32 
     33 The first line contains two space-separated integers *n* (3 ≤ *n* ≤ 105) and *m* (1 ≤ *m* ≤ 105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance.
     34 
     35 Output
     36 
     37 Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 7 3  
     45 1 2 3  
     46 1 4 5  
     47 4 6 7
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 1 2 3 3 2 2 1
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 9 3  
     60 3 6 9  
     61 2 5 8  
     62 1 4 7
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 1 1 1 2 2 2 3 3 3
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 5 2  
     75 4 1 5  
     76 3 1 2
     77 ```
     78 
     79 Output
     80 
     81 ```
     82 2 3 1 1 3
     83 ```