A14683 | Tricolor Triangles
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a simple undirected graph with $n$ vertices and $m$ edges. Edge $i$ is colored in the color $c_i$ , which is either $1$ , $2$ , or $3$ , or left uncolored (in this case, $c_i = -1$ ).
You need to color all of the uncolored edges in such a way that for any three pairwise adjacent vertices $1 \leq a < b < c \leq n$ , the colors of the edges $a \leftrightarrow b$ , $b \leftrightarrow c$ , and $a \leftrightarrow c$ are either pairwise different, or all equal. In case no such coloring exists, you need to determine that.
You need to color all of the uncolored edges in such a way that for any three pairwise adjacent vertices $1 \leq a < b < c \leq n$ , the colors of the edges $a \leftrightarrow b$ , $b \leftrightarrow c$ , and $a \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 $t$ ( $1 \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 $n$ and $m$ ( $3 \leq n \leq 64$ , $0 \leq m \leq \min(256, \frac{n(n-1)}{2})$ ): the number of vertices and edges in the graph.
Each of the next $m$ lines contains three integers $a_i$ , $b_i$ , and $c_i$ ( $1 \leq a_i, b_i \leq n$ , $a_i \ne b_i$ , $c_i$ is either $-1$ , $1$ , $2$ , or $3$ ), denoting an edge between $a_i$ and $b_i$ with color $c_i$ . It is guaranteed that no two edges share the same endpoints.
The following lines contain the description of the test cases.
In the first line you are given two integers $n$ and $m$ ( $3 \leq n \leq 64$ , $0 \leq m \leq \min(256, \frac{n(n-1)}{2})$ ): the number of vertices and edges in the graph.
Each of the next $m$ lines contains three integers $a_i$ , $b_i$ , and $c_i$ ( $1 \leq a_i, b_i \leq n$ , $a_i \ne b_i$ , $c_i$ is either $-1$ , $1$ , $2$ , or $3$ ), denoting an edge between $a_i$ and $b_i$ with color $c_i$ . It is guaranteed that no two edges share the same endpoints.
输出格式
For each test case, print $m$ integers $d_1, d_2, \ldots, d_m$ , where $d_i$ 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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted