Description

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.

Input

The first line of the input contains integers n and m(3 ≤ n ≤ 48, . Then follow m lines, each contains a pair of integers ai, bi(1 ≤ ai < bi ≤ n) — the pair ai, bi means that students with numbers ai and bi want to be on the same team.

It is guaranteed that n is divisible by 3. It is guaranteed that each pair ai, bi occurs in the input at most once.

Output

If the required division into teams doesn't exist, print number -1. Otherwise, print  lines. In each line print three integers xiyizi (1 ≤ xi, yi, zi ≤ n) — the i-th team.

If there are multiple answers, you are allowed to print any of them.

Sample Input

Input
3 0
Output
3 2 1 
Input
6 4
1 2
2 3
3 4
5 6
Output
-1
Input
3 3
1 2
2 3
1 3
Output
3 2 1 
題意:教練培訓n個同學(n%3 = 0),要給他們分組,每3個人一組,要分n/3組,輸入的m行中的x、y代表x想和y分一組,教練會根據他們的請求將他們分為一組,若最後分組不成功輸出-1,否則一一輸出各組同學的序號。 思路:先套並查集模板將可以分成一組的以鄰接表的形式存起來,然後再判斷,如果與i一組的人數大於3,說明分組不成功。具體看程式碼。
 #include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
int n,m;
int gp[][];//gp[i][j]表示j與i可以分一組
int cnt[];//cnt[i]表示與i一組的人數
int vis[];
int set[];
queue<int>que[];
int find(int x)
{
if(set[x] != x)
set[x] = find(set[x]);
return set[x];
} int main()
{
scanf("%d %d",&n,&m);
int t,flag;
for(int i = ; i <= n; i++)
set[i] = i;
int u,v;
for(int i = ; i <= m; i++)
{
scanf("%d %d",&u,&v);
int uu = find(u);
int vv = find(v);
if(uu != vv)
set[uu] = vv;
}
for(int i = ; i <= n; i++)
{
cnt[i] = ;
t = find(i);
for(int j = ; j <= n; j++)
{
if(t == find(j))
{
gp[i][cnt[i]++] = j;
}
}
}//並查集,將所有可能分一組的存起來 memset(vis,,sizeof(vis));
flag = ;
for(int i = ; i <= n; i++)
{
if(cnt[i] > )//如果與i一組的人數大於3,不合法
{
flag = ;
continue;
}
if(vis[gp[i][]]) continue; else if(cnt[i] == )
que[].push(i);
else if(cnt[i] == )
que[].push(i);
else if(cnt[i] == )
que[].push(i); vis[gp[i][]] = ;
}
if(que[].size() < que[].size() || (que[].size()-que[].size())% !=)
flag = ; if(flag)
{
while(que[].size() > )
{
int sec = que[].front();
que[].pop();
printf("%d %d ",gp[sec][],gp[sec][]); int fir = que[].front();
que[].pop();
printf("%d\n",gp[fir][]);
} while(que[].size() > )
{
int fir = que[].front();
que[].pop();
printf("%d ",gp[fir][]); fir = que[].front();
que[].pop();
printf("%d ",gp[fir][]); fir = que[].front();
que[].pop();
printf("%d\n",gp[fir][]);
} while(que[].size() > )
{
int thi= que[].front();
que[].pop();
printf("%d %d %d\n",gp[thi][],gp[thi][],gp[thi][]);
}
}
else printf("-1\n"); return ;
}