#graph502. One-Way Streets
One-Way Streets
One-Way Streets
Problem Source
CEOI 2017
Problem Description
You are given an undirected graph with vertices and edges. You want to assign a direction to every edge, turning the graph into a directed one.
There are constraints; the -th constraint is a pair , meaning that in the resulting directed graph, must be able to reach by following some directed edges.
Determine, for each edge, whether its direction is forced (uniquely determined), and if so, report that direction. A solution is guaranteed to exist.
Input Format
The first line contains two space-separated positive integers and .
The next lines each contain two space-separated positive integers , indicating an edge between and .
The next line contains one integer , the number of constraints.
The next lines each contain two space-separated positive integers , describing a constraint .
For all test cases, , and .
Output Format
Output a single line containing a string of length , the answer for each edge:
- If the -th edge must be directed from to , the -th character should be
R; - If the -th edge must be directed from to , the -th character should be
L; - Otherwise, if the -th edge's direction cannot be uniquely determined, the -th character should be
B.
Sample Input
5 6
1 2
1 2
4 3
2 3
1 3
5 1
2
4 5
1 3
Sample Output
BBRBBL