Codeforces Round 347 (Div. 2)
D
Graph Coloring
Codeforces
未评级
原题
← CE →
翻译中…

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.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 100 000$) — 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*}$ (image) 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.

翻译中…

Output

翻译中…

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.

翻译中…

样例

Input #1
3 3
1 2 B
3 1 R
3 2 B
Output #1
1
2
InputCopy OutputCopy
Input #2
6 5
1 3 R
2 3 R
3 4 B
4 5 R
4 6 R
Output #2
2
3 4
InputCopy OutputCopy
Input #3
4 5
1 2 R
1 3 R
2 3 B
3 4 B
1 4 B
Output #3
-1
InputCopy OutputCopy
题目信息
题号
664D
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。