QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100

#789. One-Way Streets

統計

很久以前,有一个国家拥有 $n$ 个城市和 $m$ 条连接它们的双向道路。技术的发展带来了更快、更大的道路车辆,这引发了一个问题——道路变得太窄,无法供两辆车向相反方向行驶。为了解决这个问题,政府决定将所有道路改为单车道、单向(定向)道路。

将道路改为单向是有代价的,因为一些原本连通的城市对在改变后可能不再可达。政府编制了一份重要的城市对列表,要求必须能够从第一个城市出发到达第二个城市。你的任务是确定每一条道路的交通方向。题目保证存在可行解。

对于某些道路,如果你想获得一个可行解,其交通方向是别无选择的。交通流将从第一个城市流向第二个城市(右方向,用字母 R 表示),或者从第二个城市流向第一个城市(左方向,用字母 L 表示)。然而,对于某些道路,存在一种该道路向左的解,同时也存在另一种(可能不同的)该道路向右的解。你应该用字母 B 来表示这类道路,意为两种方向均可。

输出一个长度为 $m$ 的字符串。其第 $i$ 个字符应为:

  • R:如果所有可行解都要求第 $i$ 条道路向右。
  • L:如果所有可行解都要求第 $i$ 条道路向左。
  • B:如果存在一种可行解使得第 $i$ 条道路向左,且同时也存在一种可行解使得第 $i$ 条道路向右。

输入格式

第一行包含城市数量 $n$ 和道路数量 $m$。接下来的 $m$ 行描述了道路,每行包含一对数字 $a_i$ 和 $b_i$,表示城市 $a_i$ 和 $b_i$ 之间有一条道路。同一对城市之间可能存在多条道路,道路甚至可以连接同一个城市。

下一行包含必须可达的城市对数量 $p$。接下来的 $p$ 行包含城市对 $x_i$ 和 $y_i$,意味着必须存在一条从城市 $x_i$ 出发到达 $y_i$ 的路径。

数据范围

  • $1 \le n, m, p \le 100\,000$
  • $1 \le a_i, b_i, x_i, y_i \le n$

子任务

  • 子任务 1(30 分):$n, m \le 1000$,$p \le 100$
  • 子任务 2(30 分):$p \le 100$
  • 子任务 3(40 分):无额外限制

输出格式

输出一个长度为 $m$ 的字符串,如题目描述中所述。

样例

输入 1

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

输出 1

BBRBBL

说明 1

让我们展示第五条道路 "1 3" 可以被定向为任一方向。两种可能的道路定向方案中,第五条道路的方向分别为 LLRLRL 和 RLRRLL。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.