CF1616F.Tricolor Triangles

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

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 1≤a<b<c≤n1 \leq a \lt b \lt c \leq n, the colors of the edges a↔ba \leftrightarrow b, b↔cb \leftrightarrow c, and a↔ca \leftrightarrow c are either pairwise different, or all equal. In case no such coloring exists, you need to determine that.

给你一个包含 nn 个顶点和 mm 条边的简单无向图。第 ii 条边被染成颜色 cic_i,该颜色为 11、22 或 33 中的一个,或者未染色(此时 ci=−1c_i = -1)。

你需要将所有未染色的边进行染色,使得对任意三个两两相邻的顶点 1≤a<b<c≤n1 \leq a \lt b \lt c \leq n,边 a↔ba \leftrightarrow b、b↔cb \leftrightarrow c 和 a↔ca \leftrightarrow c 的颜色要么互不相同,要么全部相等。若不存在满足条件的染色方案,则需判定这一点。

输入格式

The first line of input contains one integer tt (1≤t≤101 \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 (3≤n≤643 \leq n \leq 64, 0≤m≤min⁡(256,n(n−1)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 (1≤ai,bi≤n1 \leq a_i, b_i \leq n, ai≠bia_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.

输入的第一行包含一个整数 tt(1≤t≤101 \leq t \leq 10):测试用例的数量。

接下来的若干行描述各测试用例。

第一行给出两个整数 nn 和 mm(3≤n≤643 \leq n \leq 64,0≤m≤min⁡(256,n(n−1)2)0 \leq m \leq \min(256, \frac{n(n-1)}{2})):图中顶点数和边数。

接下来的 mm 行中,每行包含三个整数 aia_i、bib_i 和 cic_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,ai≠bia_i \ne b_i,且 cic_i 的取值为 −1-1、11、22 或 33),表示一条连接顶点 aia_i 与 bib_i 的边,其颜色为 cic_i。保证不存在两条边具有完全相同的两个端点。

输出格式

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.

对于每个测试用例,输出 mm 个整数 d1,d2,…,dmd_1, d_2, \ldots, d_m,其中 did_i 表示你最终染色方案中第 ii 条边的颜色。如果不存在合法的完成染色方案,则输出 −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

输入解题思路,AI测评打分。不知道怎么写?

首页