301886: CF357B. Flag Day

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Flag Day

题意翻译

### 题意翻译 有 $n$ 个人,分成 $m$ 组,每组有三个人,一个人可以出现在多个组中,组内人不会重复。每个人代表$1$,$2$,$3$中的一个,每个组里三个数字必须各出现一次。问给每个人分配的数字是什么。 ### 输入 第一行有两个数 $n$ 和 $m$,分别代表人数和组数。接下来 $m$ 行每行有$3$个数代表第 $i$ 个组里的$3$个人。 ### 输出 一共 $n$ 个数,代表第 $i$ 个人分配的数字。 ### 数据范围 $3 \leqslant n \leqslant 10^5$,$1 \leqslant m \leqslant 10^5$

题目描述

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 $ m $ 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 $ n $ dancers, and their number can be less than $ 3m $ . 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 $ 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.

输入输出格式

输入格式


The first line contains two space-separated integers $ n $ ( $ 3<=n<=10^{5} $ ) and $ m $ ( $ 1<=m<=10^{5} $ ) — 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.

输出格式


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.

输入输出样例

输入样例 #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 

Input

题意翻译

### 题意翻译 有 $n$ 个人,分成 $m$ 组,每组有三个人,一个人可以出现在多个组中,组内人不会重复。每个人代表$1$,$2$,$3$中的一个,每个组里三个数字必须各出现一次。问给每个人分配的数字是什么。 ### 输入 第一行有两个数 $n$ 和 $m$,分别代表人数和组数。接下来 $m$ 行每行有$3$个数代表第 $i$ 个组里的$3$个人。 ### 输出 一共 $n$ 个数,代表第 $i$ 个人分配的数字。 ### 数据范围 $3 \leqslant n \leqslant 10^5$,$1 \leqslant m \leqslant 10^5$

加入题单

算法标签: