CF357B.Flag Day
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
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 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 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.
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.
在贝尔兰,即将到来的是国庆日——国旗日。为庆祝这一盛事,该国总统决定举办一场大型舞会,并委托贵机构负责组织。他提出了以下几项要求:
- 整场舞会总共必须有 m 支舞蹈;
- 每支舞蹈必须恰好由三人参与;
- 每支舞蹈中必须有一名身着白色服装的舞者、一名身着红色服装的舞者和一名身着蓝色服装的舞者(这三种颜色即贝尔兰国旗的颜色)。
贵机构共有 n 名舞者,而该人数可能少于 3m。也就是说,部分舞者很可能需要参加多支舞蹈。所有 n 名舞者都必须参与舞会表演。然而,若某支舞蹈中有两名或以上舞者曾共同参与过之前的某支舞蹈,则这支舞蹈将不再具有观赏性。贵机构不允许此类情况发生,因此:每支舞蹈中至多只允许有一名舞者曾在之前的任意一支舞蹈中出现过。
贵机构已综合考虑全部条件,并制定了 m 支舞蹈的完整方案:每支舞蹈均指定了三名参与舞者。现在,您的任务是为这 n 名舞者分别确定其服装颜色(白、红或蓝),使得总统提出的第三项条件得以满足:即每支舞蹈中都恰好包含一名穿白色、一名穿红色和一名穿蓝色服装的舞者。注意:每位舞者在整个舞会过程中不可更换服装。
输入格式
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.
第一行包含两个以空格分隔的整数 n(3 ≤ n ≤ 105)和 m(1 ≤ m ≤ 105),分别表示舞者人数和舞蹈场次数。接下来有 m 行,按舞蹈进行的顺序描述每一场舞蹈。第 i 行包含三个互不相同的整数,表示参与第 i 场舞蹈的三位舞者的编号。舞者编号为 1 到 n。每位舞者至少参加一场舞蹈。
输出格式
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.
输出 n 个用空格分隔的整数:其中第 i 个数表示第 i 位舞者服装的颜色(1 表示白色,2 表示红色,3 表示蓝色)。若存在多个合法解,输出任意一个即可。题目保证至少存在一个解。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?