Trokuti

시간 제한4초메모리 제한1024 MB

요약
6N개의 정점으로 이루어진 그래프가 2N개의 서로소 삼각형으로 분할 가능할 때, 그중 N개의 서로소 삼각형을 찾아 출력한다.
난이도

보통10점 중 7점

유형
그래프, 그리디, 구현
정답자
아직 제출이 없습니다

문제

An undirected graph with 6⋅N6 \cdot N vertices and MM edges is given. An additional property of the graph is that it can be partitioned into 2⋅N2 \cdot N disjoint triangles.

Find NN disjoint triangles in the graph.

입력

In the first line, there is a natural number TT (1≤T≤1001 ≤ T ≤ 100), which indicates the number of test cases.

This is followed by TT blocks of data.

In the first line of each block, there are natural numbers NN and MM (1≤N≤3001 ≤ N ≤ 300, 0≤M≤1060 ≤ M ≤ 10^6).

In the next MM lines, there are two natural numbers xx and yy (1≤x,y≤6⋅N1 ≤ x, y ≤ 6 \cdot N), which indicate that there is an edge between vertices xx and yy.

The sum of all values of NN across all test cases will not exceed 300300.

출력

For each test case, output NN lines, each line containing three natural numbers aa, bb, cc (1≤a,b,c≤6⋅N1 ≤ a, b, c ≤ 6 \cdot N), which indicate that the vertices aa, bb, and cc form a triangle.

예제2

  1. 예제 1

    입력
    1
    1 6
    1 2
    2 3
    1 3
    4 5
    4 6
    5 6
    
    예상 출력
    1 2 3
    
  2. 예제 2

    입력
    1
    3 26
    4 7
    4 9
    7 9
    4 5
    4 8
    5 8
    4 12
    4 18
    12 18
    3 7
    3 9
    15 5
    15 8
    6 13
    6 1
    13 1
    6 14
    6 17
    14 17
    6 2
    6 10
    2 10
    16 13
    16 1
    11 14
    11 17
    
    예상 출력
    1 6 13
    3 7 9
    4 5 8