CF1616F.Tricolor Triangles

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a simple undirected graph with nn vertices and mm edges. Edge ii is colored in the color cic_i , which is either 11 , 22 , or 33 , or left uncolored (in this case, ci=1c_i = -1 ).

You need to color all of the uncolored edges in such a way that for any three pairwise adjacent vertices 1a<b<cn1 \leq a < b < c \leq n , the colors of the edges aba \leftrightarrow b , bcb \leftrightarrow c , and aca \leftrightarrow c are either pairwise different, or all equal. In case no such coloring exists, you need to determine that.

输入格式

The first line of input contains one integer tt ( 1t101 \leq t \leq 10 ): the number of test cases.

The following lines contain the description of the test cases.

In the first line you are given two integers nn and mm ( 3n643 \leq n \leq 64 , 0mmin(256,n(n1)2)0 \leq m \leq \min(256, \frac{n(n-1)}{2}) ): the number of vertices and edges in the graph.

Each of the next mm lines contains three integers aia_i , bib_i , and cic_i ( 1ai,bin1 \leq a_i, b_i \leq n , aibia_i \ne b_i , cic_i is either 1-1 , 11 , 22 , or 33 ), denoting an edge between aia_i and bib_i with color cic_i . It is guaranteed that no two edges share the same endpoints.

输出格式

For each test case, print mm integers d1,d2,,dmd_1, d_2, \ldots, d_m , where did_i is the color of the ii -th edge in your final coloring. If there is no valid way to finish the coloring, print 1-1 .

输入输出样例

  • 输入#1

    4
    3 3
    1 2 1
    2 3 2
    3 1 -1
    3 3
    1 2 1
    2 3 1
    3 1 -1
    4 4
    1 2 -1
    2 3 -1
    3 4 -1
    4 1 -1
    3 3
    1 2 1
    2 3 1
    3 1 2

    输出#1

    1 2 3 
    1 1 1 
    1 2 2 3 
    -1
首页