#ARC161E. [ARC161E] Not Dyed by Majority (Cubic Graph)
[ARC161E] Not Dyed by Majority (Cubic Graph)
Score : points
Problem Statement
You are given a connected simple undirected graph with vertices and edges, where is a positive even number. The vertices are labeled from to , and the -th edge connects vertex and vertex . Moreover, for every vertex, the number of incident edges is exactly 3.
You will color each vertex of the given graph either black ( B
) or white ( W
).
Here, the string obtained by arranging the colors ( B
or W
) of the vertices in the order of vertex labels is called a color sequence.
Determine whether there is a color sequence that cannot result from performing the following operation once when all vertices are colored, and if there is such a color sequence, find one.
Operation: For each vertex , let be the color that occupies the majority (more than half) of the colors of the vertices connected to by an edge. For every vertex , change its color to simultaneously.
There are test cases to solve.
Constraints
- The sum of over the test cases in each input file is at most .
- is an even number.
- The given graph is connected.
- Each vertex appears exactly 3 times as .
Input
The input is given from Standard Input in the following format:
Each test case is in the following format:
Output
Print lines.
For the -th line, if there is a color sequence that cannot result from performing the operation for the -th test case, print such a color sequence; otherwise, print -1
.
If there are multiple color sequences that cannot result from performing the operation, any of them will be considered correct.
Let us consider the first test case.
For the color of vertex to be B
, at least two of the colors of vertices must be B
before the operation.
Then, for at least one of the vertices , at least two of the colors of the vertices connected to that vertex by an edge are B
, so the color of that vertex after the operation will be B
.
Therefore, the color sequence BWWW
cannot result from performing the operation.