#P10097. Point Coloring in Directed Graphs

    ID: 12081 Type: Default 1000ms 256MiB

Point Coloring in Directed Graphs

Point Coloring in Directed Graphs

You are given a directed graph with n vertices and m edges. Each vertex is to be colored with one of three colors based on the following rules:

  • Green: If there exists a cycle that goes through the vertex (i.e. there is a path from the vertex back to itself). In such a case, by repeatedly traversing the cycle, the vertex can appear as the starting point an infinite number of times.
  • Blue: If the vertex is not green and has at least one outgoing edge (i.e. it can be used as a starting point one more time), then the vertex is colored blue.
  • Red: Otherwise, if the vertex has no outgoing edge, it is colored red.

Determine the color of each vertex.

Note: A cycle may consist of more than one vertex or even a single vertex with a self-loop. Use LaTeX for formulas where needed, for example, a cycle condition can be represented as: \(i \rightarrow \cdots \rightarrow i\).

inputFormat

The input begins with a line containing two integers n and m — the number of vertices and the number of edges.

Each of the next m lines contains two integers u and v representing a directed edge from vertex u to vertex v.

outputFormat

Output a single line containing n space-separated words. The i-th word should be the color assigned to vertex i (either Green, Blue, or Red).

sample

3 3
1 2
2 3
3 1
Green Green Green