A10466 | Graph Coloring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an undirected graph that consists of $n$ vertices and $m$ edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edges with an endpoint in this vertex change the color to red.
Find the minimum possible number of moves required to make the colors of all edges equal.
Find the minimum possible number of moves required to make the colors of all edges equal.
输入格式
The first line of the input contains two integers $n$ and $m$ ( $1<=n,m<=100000$ ) — the number of vertices and edges, respectively.
The following $m$ lines provide the description of the edges, as the $i$ -th of them contains two integers $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ , $u_{i}≠v_{i}$ ) — the indices of the vertices connected by the $i$ -th edge, and a character $c_{i}$ () providing the initial color of this edge. If $c_{i}$ equals 'R', then this edge is initially colored red. Otherwise, $c_{i}$ is equal to 'B' and this edge is initially colored blue. It's guaranteed that there are no self-loops and multiple edges.
The following $m$ lines provide the description of the edges, as the $i$ -th of them contains two integers $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ , $u_{i}≠v_{i}$ ) — the indices of the vertices connected by the $i$ -th edge, and a character $c_{i}$ () providing the initial color of this edge. If $c_{i}$ equals 'R', then this edge is initially colored red. Otherwise, $c_{i}$ is equal to 'B' and this edge is initially colored blue. It's guaranteed that there are no self-loops and multiple edges.
输出格式
If there is no way to make the colors of all edges equal output $-1$ in the only line of the output. Otherwise first output $k$ — the minimum number of moves required to achieve the goal, then output $k$ integers $a_{1},a_{2},...,a_{k}$ , where $a_{i}$ is equal to the index of the vertex that should be used at the $i$ -th move.
If there are multiple optimal sequences of moves, output any of them.
If there are multiple optimal sequences of moves, output any of them.
输入输出样例
输入 #1
3 3 1 2 B 3 1 R 3 2 B
输出 #1
1 2
输入 #2
6 5 1 3 R 2 3 R 3 4 B 4 5 R 4 6 R
输出 #2
2 3 4
输入 #3
4 5 1 2 R 1 3 R 2 3 B 3 4 B 1 4 B
输出 #3
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted