CF662B.Graph Coloring

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an undirected graph that consists of nn vertices and mm 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 nn and mm ( 1<=n,m<=1000001<=n,m<=100000 ) — the number of vertices and edges, respectively.

The following mm lines provide the description of the edges, as the ii -th of them contains two integers uiu_{i} and viv_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n , uiviu_{i}≠v_{i} ) — the indices of the vertices connected by the ii -th edge, and a character cic_{i} () providing the initial color of this edge. If cic_{i} equals 'R', then this edge is initially colored red. Otherwise, cic_{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-1 in the only line of the output. Otherwise first output kk — the minimum number of moves required to achieve the goal, then output kk integers a1,a2,...,aka_{1},a_{2},...,a_{k} , where aia_{i} is equal to the index of the vertex that should be used at the ii -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
    
首页