303418: CF662B. Graph Coloring
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Graph Coloring
题意翻译
# 题目描述 给出一个$n$个点,$m$条边的无向图,一开始每条边可能是红色或者蓝色,翻转一个点可以使相连的边变成相反的颜色,希望能够把全部边变成红色或者蓝色 问最少需要翻转的点数,并给出具体的方案 --- # 输入输出格式 ## 输入格式 第一行输入$n,m$,分别表示点的数量和边的数量$(1\leq n,m\leq 100000)$ 第二至$m+1$行$ui,vi,ci$,分别表示无向边的两个点以及它的颜色,保证没有重边和自环 ## 输出格式 如果没有方法使其合法输出$-1$, 否则第一行输出最少需要翻转的点数,第二行用空格分隔输出翻转点的编号,只需要输出一种方案题目描述
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.输入输出格式
输入格式
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} $ (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF662B/427b9b8bbbd6a7ee3970807ed458245f7bc435be.png)) 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.
输入输出样例
输入样例 #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