#P4652. [CEOI 2017] One-Way Streets
[CEOI 2017] One-Way Streets
Description
You are given an undirected graph with vertices and edges. Now you want to orient this graph.
There are constraints. Each constraint is of the form , meaning that in the new directed graph, must be able to reach 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 separated by spaces.
The next lines each contain two positive integers separated by spaces, indicating that there is an edge between and .
The next line contains one integer , the number of constraints.
The next lines each contain two positive integers separated by spaces, describing a constraint .
Output Format
Output one line containing a string of length , representing the answer for each edge:
-
If the -th edge must be directed from to , then the -th character should be
R. -
If the -th edge must be directed from to , then the -th character should be
L. -
Otherwise, if the direction of the -th edge cannot be uniquely determined, then the -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, ; .
Translated by ChatGPT 5
京公网安备 11011102002149号