#P11022. 「LAOI-6」Yet Another Graph Coloration Problem
「LAOI-6」Yet Another Graph Coloration Problem
Description
Little R has a simple undirected graph with nodes and edges, in which the nodes are numbered . She wants to assign a black or white color to each node in the graph, so that:
- There is at least one black node.
- There is at least one white node.
- For each pair of nodes , if the color of nodes and are different, there are at least two different simple paths from to .
- A simple path is a path that does not go through the same node repeatedly on the graph.
- Two simple paths are considered different, if and only if, either their lengths are different, or there exists at least one positive integer such that the -th node that the two paths pass through are different.
Alternatively, report that there is no solution.
Input Format
Each test contains multiple testcases.
The first line of the input contains an integer — the number of test cases. The description of test cases follows.
- The first line of each test case contains two integers — the number of nodes and edges.
- Then, lines follow, each line contains two integers , describing the edges.
It is guaranteed that there are no multiple edges or self-loops in the graph.
Output Format
For each test case:
- If there exists a way to assign the colors, output a string of length consisting of characters
BWonly, where the -th node is black if the -th character isB, and white if it isW; - If there is no solution, output a single line containing an integer .
3
4 5
1 2
1 3
1 4
2 3
3 4
5 6
1 2
1 3
1 5
2 3
2 4
3 4
6 10
1 2
1 3
1 5
2 3
2 4
2 5
2 6
3 5
3 6
4 6
BWBW
BBWWB
BWBWBW
1
4 3
1 2
1 3
2 3
-1
Hint
Subtasks are used in this problem.
- Subtask 0 (15 pts): .
- Subtask 1 (25 pts): , , , .
- Subtask 2 (5 pts): It is guaranteed that the given graph is not connected.
- Subtask 3 (10 pts): It is guaranteed that the degree of each node is .
- Subtask 4 (20 pts): It is guaranteed that .
- Subtask 5 (25 pts): No additional constraint.
For all tests, , , . It is guaranteed that , , and there are no multiple edges or self-loops in the graph.
京公网安备 11011102002149号