CF300B.Coach
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
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.
Help the coach and divide the teams the way he wants.
一名编程教练有 n 名学生需要教授。已知 n 能被 3 整除。假设所有学生编号为 1 到 n(含端点)。
在大学编程锦标赛开始前,教练希望将所有学生分成若干个三人小组。对于某些学生对,我们知道他们希望被分在同一支队伍中。此外,若第 i 名学生希望与第 j 名学生同队,则第 j 名学生也一定希望与第 i 名学生同队。教练希望各支队伍能取得良好成绩,因此要求满足如下条件:若第 i 名学生希望与第 j 名学生同队,则第 i 名与第 j 名学生必须被分在同一支队伍中。同时,显然每名学生必须且仅能属于一支队伍。
请帮助教练按其要求完成分组。
输入格式
The first line of the input contains integers n and m (3 ≤ n ≤ 48,
. 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.
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.
输入的第一行包含两个整数 n 和 m(3≤n≤48,
)。接下来是 m 行,每行包含一对整数 ai,bi(1≤ai<bi≤n)—— 这对 ai,bi 表示编号为 ai 和 bi 的学生希望被分在同一支队伍中。
保证 n 能被 3 整除。保证每对 ai,bi 在输入中至多出现一次。
输出格式
If the required division into teams doesn't exist, print number -1. Otherwise, print
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.
If there are multiple answers, you are allowed to print any of them.
如果不存在满足要求的分组方案,则输出数字 -1。否则,输出
行。每行输出三个整数 xi、yi、zi(1 ≤ xi, yi, zi ≤ n),表示第 i 个队伍。
若存在多种答案,输出任意一种即可。
输入输出样例
输入#1
3 0
输出#1
3 2 1
输入#2
6 4 1 2 2 3 3 4 5 6
输出#2
-1
输入#3
3 3 1 2 2 3 1 3
输出#3
3 2 1
输入解题思路,AI测评打分。不知道怎么写?