CF1616F.Tricolor Triangles
普及/提高-
通过率:0%
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.
输入格式
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.
输出格式
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 .
输入输出样例
输入#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