LED-led Paths
Time limit3sMemory limit512 MB
Color each directed edge of an acyclic graph red, green, or blue so that no single-color directed path has more than 42 edges.
- Level
Hard9 of 10
- Topics
- Graph, Topological sort, Dynamic programming
- Solved
- No attempts yet
Problem
A large city has junctions and one-way streets connecting them. The city has no directed cycles, so one cannot walk along the streets forever.
The tourism department will light each street with one of three colors: red (R), green (G), or blue (B). The official tourist maps show the chosen colors. Every continuous path whose streets all share one color is suggested for walking and sightseeing. These paths are called LED-led paths.
The health department warns that a very long single-color path may tempt tourists to overestimate their strength, walk too long, and grow tired of the city.
Propose a three-color illumination plan in which no single-color LED-led path consists of more than 42 streets.
Input
The first line contains two integers and , the number of junctions and streets (, ).
Each of the following lines contains two integers and , denoting a one-way street from junction to junction (; ).
The given city is guaranteed to be acyclic. Each pair of junctions is connected by at most one street.
Output
For each street, in the order of input, print its color on a separate line: a single letter R, G, or B.
Hint
In this example, every single-color LED-led path is at most one street long, so none exceeds the 42-street limit set by the health department.