CF357B.Flag Day

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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:

  • overall, there must be mm dances;
  • exactly three people must take part in each dance;
  • 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).

The agency has nn dancers, and their number can be less than 3m3m . 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.

You considered all the criteria and made the plan for the mm dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the nn 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.

输入格式

The first line contains two space-separated integers nn ( 3<=n<=1053<=n<=10^{5} ) and mm ( 1<=m<=1051<=m<=10^{5} ) — the number of dancers and the number of dances, correspondingly. Then mm lines follow, describing the dances in the order of dancing them. The ii -th line contains three distinct integers — the numbers of the dancers that take part in the ii -th dance. The dancers are numbered from 11 to nn . Each dancer takes part in at least one dance.

输出格式

Print nn space-separated integers: the ii -th number must represent the color of the ii -th dancer's clothes ( 11 for white, 22 for red, 33 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.

输入输出样例

  • 输入#1

    7 3
    1 2 3
    1 4 5
    4 6 7
    

    输出#1

    1 2 3 3 2 2 1 
    
  • 输入#2

    9 3
    3 6 9
    2 5 8
    1 4 7
    

    输出#2

    1 1 1 2 2 2 3 3 3 
    
  • 输入#3

    5 2
    4 1 5
    3 1 2
    

    输出#3

    2 3 1 1 3 
    
首页