QOJ.ac

QOJ

Limite de temps : 4.0 s Limite de mémoire : 512 MB Points totaux : 100

#11740. Code-Cola 植物

Statistiques

Berland 由 $n$ 个城市组成,编号为 $1$ 到 $n$。城市之间有 $m$ 条有向道路。Berland 的道路中不存在有向环。

Berland 有两座 Code-Cola 工厂。第一座是生产工厂,位于城市 $a$;第二座是回收工厂,位于城市 $b$。

Code-Cola 公司决定使用 $n-1$ 条道路进行配送。使用这组道路,必须能够从生产工厂(即城市 $a$)到达所有 $n$ 个城市。此外,Code-Cola 公司还决定使用另外 $n-1$ 条道路,由回收卡车将空的 Code-Cola 瓶子运送到回收工厂。使用这第二组道路,必须能够从所有 $n$ 个城市到达回收工厂(即城市 $b$)。

请帮助 Code-Cola 公司找到两组不相交的道路,使得:

  • 每一组都包含 $n-1$ 条道路;
  • 沿着第一组道路,可以从城市 $a$ 到达任何城市;
  • 沿着第二组道路,可以从任何城市到达城市 $b$。

输入格式

输入包含一个或多个测试用例。每个测试用例的格式描述如下。

每个测试用例的第一行包含四个整数:$n$(Berland 的城市数量)、$m$(道路数量)、$a$(生产工厂所在的城市)和 $b$(回收工厂所在的城市)($2 \le n \le 5 \cdot 10^5$,$1 \le m \le 10^6$,$1 \le a, b \le n$)。$a$ 和 $b$ 可能相等。

接下来的 $m$ 行包含道路的描述,每行一条。第 $i$ 条描述包含两个整数 $x_i$ 和 $y_i$,表示有一条从 $x_i$ 到 $y_i$ 的有向(单向)道路($1 \le x_i, y_i \le n$)。保证 Berland 的道路中不存在有向环。在两个城市之间,可能存在多条方向相同的道路。

所有测试用例中 $n$ 的总和不超过 $5 \cdot 10^5$。所有测试用例中 $m$ 的总和不超过 $10^6$。测试用例之间没有特殊的分隔符。

输出格式

对于每个测试用例,按以下方式输出答案:

如果存在解,输出一行 “YES”,随后输出两行,每行包含 $n-1$ 个道路编号。第一行描述第一组道路,第二行描述第二组道路。所有 $2 \cdot (n-1)$ 个编号必须互不相同。道路按输入中出现的顺序从 $1$ 到 $m$ 编号。你可以按任意顺序输出一行中的数字。如果存在多个可能的解,输出其中任意一个即可。

如果不存在解,输出一行 “NO”。

样例

输入 1

4 7 1 4
1 2
1 2
1 4
2 3
2 3
3 4
3 4
4 3 1 2
1 2
2 4
4 3
5 8 3 1
3 2
5 2
3 4
4 5
4 1
2 1
3 5
3 1

输出 1

YES
2 5 6
3 7 4
NO
YES
1 3 4 8
5 6 2 7

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#206EditorialOpen题解jiangly2025-12-13 00:12:42View

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.