CF1616F.Tricolor Triangles
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a simple undirected graph with n vertices and m edges. Edge i is colored in the color ci, which is either 1, 2, or 3, or left uncolored (in this case, ci=−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≤n, the colors of the edges a↔b, b↔c, and a↔c are either pairwise different, or all equal. In case no such coloring exists, you need to determine that.
给你一个包含 n 个顶点和 m 条边的简单无向图。第 i 条边被染成颜色 ci,该颜色为 1、2 或 3 中的一个,或者未染色(此时 ci=−1)。
你需要将所有未染色的边进行染色,使得对任意三个两两相邻的顶点 1≤a<b<c≤n,边 a↔b、b↔c 和 a↔c 的颜色要么互不相同,要么全部相等。若不存在满足条件的染色方案,则需判定这一点。
输入格式
The first line of input contains one integer t (1≤t≤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 n and m (3≤n≤64, 0≤m≤min(256,2n(n−1))): the number of vertices and edges in the graph.
Each of the next m lines contains three integers ai, bi, and ci (1≤ai,bi≤n, ai=bi, ci is either −1, 1, 2, or 3), denoting an edge between ai and bi with color ci. It is guaranteed that no two edges share the same endpoints.
输入的第一行包含一个整数 t(1≤t≤10):测试用例的数量。
接下来的若干行描述各测试用例。
第一行给出两个整数 n 和 m(3≤n≤64,0≤m≤min(256,2n(n−1))):图中顶点数和边数。
接下来的 m 行中,每行包含三个整数 ai、bi 和 ci(1≤ai,bi≤n,ai=bi,且 ci 的取值为 −1、1、2 或 3),表示一条连接顶点 ai 与 bi 的边,其颜色为 ci。保证不存在两条边具有完全相同的两个端点。
输出格式
For each test case, print m integers d1,d2,…,dm, where di is the color of the i-th edge in your final coloring. If there is no valid way to finish the coloring, print −1.
对于每个测试用例,输出 m 个整数 d1,d2,…,dm,其中 di 表示你最终染色方案中第 i 条边的颜色。如果不存在合法的完成染色方案,则输出 −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测评打分。不知道怎么写?