#P8076. Graph Edge Coloring

    ID: 21260 Type: Default 1000ms 256MiB

Graph Edge Coloring

Graph Edge Coloring

Given an undirected graph with \(N\) nodes and \(E\) edges, you are to color each edge either red (R) or blue (B). The goal is to ensure that for every node whose degree is at least 2, there is at least one red edge and at least one blue edge incident to that node. If there is no valid coloring, output 0.

Note: Nodes with degree less than 2 have no color requirement.

Input Format: The first line contains two integers \(N\) and \(E\). Each of the next \(E\) lines contains two integers \(u\) and \(v\) denoting an undirected edge between nodes \(u\) and \(v\). Nodes are 1-indexed.

Output Format: If a valid coloring exists, output \(E\) tokens (each either R or B) in the same order as the input edges, separated by spaces. If no valid coloring exists, output a single 0.

inputFormat

The first line contains two integers \(N\) and \(E\). Each of the following \(E\) lines contains two integers \(u\) and \(v\) representing an edge of the graph.

outputFormat

If a valid edge coloring exists, output a single line containing \(E\) tokens (each either R or B) separated by spaces corresponding to the color of each edge in the order of input. Otherwise, output a single 0.

sample

4 3
1 2
1 3
1 4
R B R

</p>