#P4652. [CEOI 2017] One-Way Streets

[CEOI 2017] One-Way Streets

Description

You are given an undirected graph with nn vertices and mm edges. Now you want to orient this graph.

There are pp constraints. Each constraint is of the form (xi,yi)(x_i, y_i), meaning that in the new directed graph, xix_i must be able to reach yiy_i by following some directed edges.

Please determine whether the direction of each edge can be uniquely determined. Also output the direction of those edges whose directions are uniquely determined.

It is guaranteed that a solution exists.

Input Format

The first line contains two positive integers n,mn, m separated by spaces.

The next mm lines each contain two positive integers ai,bia_i, b_i separated by spaces, indicating that there is an edge between aia_i and bib_i.

The next line contains one integer pp, the number of constraints.

The next pp lines each contain two positive integers xi,yix_i, y_i separated by spaces, describing a constraint (xi,yi)(x_i, y_i).

Output Format

Output one line containing a string of length mm, representing the answer for each edge:

  • If the ii-th edge must be directed from aia_i to bib_i, then the ii-th character should be R.

  • If the ii-th edge must be directed from bib_i to aia_i, then the ii-th character should be L.

  • Otherwise, if the direction of the ii-th edge cannot be uniquely determined, then the ii-th character should be B.

5 6
1 2
1 2
4 3
2 3
1 3
5 1
2
4 5
1 3
BBRBBL

Hint

Constraints: for all testdata, 1n,m,p1000001 \le n, m, p \le 100\,000; 1ai,bi,xi,yin1 \le a_i, b_i, x_i, y_i \le n.

Translated by ChatGPT 5