#P3496. Graph Coloring with Local Constraint Conditions

    ID: 16750 Type: Default 1000ms 256MiB

Graph Coloring with Local Constraint Conditions

Graph Coloring with Local Constraint Conditions

King Byteasar is troubled once again. In his kingdom there are \( n \) towns connected by bidirectional roads. Two powerful guilds have demanded that every town either have an office for the guild or be directly connected to a town that does. However, the king is wary of corruption: if a town were to have offices of both guilds, it might give rise to a clothing cartel.

To investigate, you are given an undirected graph and must color each vertex with one of three colors: black, white, or gray. The coloring must satisfy the following conditions:

  • Every black vertex must have at least one white neighbor. Formally, if vertex \( v \) is black then \( \exists u \in N(v) \) such that \( u \) is white.
  • Every white vertex must have at least one black neighbor. That is, if vertex \( v \) is white then \( \exists u \in N(v) \) such that \( u \) is black.
  • Every gray vertex must have at least one neighbor of each color (black, white, and gray). In other words, if vertex \( v \) is gray then \( \{\text{colors of } u: u \in N(v)\} \) must contain black, white, and gray.

Your task is to determine if there exists a valid coloring that meets these conditions. If a valid coloring exists, output "Yes" followed by a valid assignment of colors to each vertex. Otherwise, output "No".

inputFormat

The input begins with a line containing two integers \( n \) and \( m \) (the number of vertices and the number of edges, respectively). Each of the next \( m \) lines contains two integers \( u \) and \( v \) (1-based indices) indicating that there is an undirected edge between vertices \( u \) and \( v \).

It is guaranteed that \( 1 \le n \le 10 \) so that a brute force solution is feasible.

outputFormat

If a valid coloring exists, output "Yes" on the first line. On the second line, output \( n \) space-separated characters, each being one of 'B' (black), 'W' (white), or 'G' (gray), representing the color assigned to vertices 1 through \( n \) respectively. If no valid coloring exists, output a single line containing "No".

sample

2 1
1 2
Yes

B W

</p>