A9047 | Coach
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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.
输出格式
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.
If there are multiple answers, you are allowed to print any of them.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted