Red-Black Tree

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Consider a binary rooted tree: a vertex is selected as the root, all edges go in the direction from the root, and each vertex has zero, one, or two children. We will say that each vertex has exactly two outgoing edges: in case it has less than two children, the remaining edges go into the void.

We will say a tree is red-black if the following conditions are satisfied:

  • Each vertex is colored either red or black.
  • There is no edge in the tree which has two red endpoints. The void is considered black.
  • Consider all paths along the edges which go from the root to the void. The number of black vertices is the same on all such paths.

A similar coloring scheme can be used in binary search trees to make them balanced.

You are given a non-empty binary rooted tree. Color its vertices so that it becomes a red-black tree, or determine that it is impossible.

입력

The first line contains an integer nn (1n5001 \le n \le 500), the number of vertices in the tree. The vertices are numbered by integers from 11 to nn.

The next line contains nn space-separated integers: p_1p\_1, p_2p\_2, \ldots, p_np\_n (0p_in0 \le p\_i \le n). A number p_i>0p\_i > 0 means that vertex ii is a child of vertex p_ip\_i. In case p_i=0p\_i = 0 means that ii is the root of the tree.

It is guaranteed that the input specifies a valid binary rooted tree: there is exactly one root, each vertex has from 00 to 22 children, and it is possible to arrive at any vertex by starting at the root and moving along the edges.

출력

If it is possible to color the tree so that it becomes a red-black tree, print any such coloring as a line of nn characters. The character at ii-th position must be "R" if vertex ii is red, or "B" if it is black.

If it is not possible to color the tree, print "Impossible".