QOJ.ac

QOJ

Time Limit: 0.2 s Memory Limit: 1024 MB Total points: 100

#4957. 协助交通

Statistics

Nlogonia 的总统颁布法令,要求 Nlogonia 的所有街道都改为单行道。由于缺乏基础科学知识,这些改动缺乏合理的规划。新系统实施后,人们发现无法去上班,或者无法从单位回家。结果,许多城市陷入了混乱和骚乱。

总统被弹劾,新政府聘请了一支科学家团队来解决这个问题。委员会随后聘请了作为算法复杂度专家的你,来帮助他们高效地计算解决方案。

对于每个城市,你将获得该城市的参考点以及单行道,每条街道连接两个参考点。你的任务是确定为了使城市实现完全连通,最少需要建造多少座单行桥梁。每座桥梁也应连接两个参考点。

输入格式

输入的第一行包含两个整数 $N$ 和 $M$ ($1 \le N \le 10^4, 1 \le M \le 10^6$),其中 $N$ 是参考点的数量,$M$ 是街道的数量。接下来的 $M$ 行中,每一行包含两个整数 $R$ 和 $S$ ($1 \le R, S \le N, R \neq S$),对应一条从 $R$ 连接到 $S$ 的街道,这意味着该街道上的每辆车都必须从 $R$ 驶向 $S$。

输出格式

你的程序必须输出一行,包含为了让居民满意而必须建造的最少桥梁数量。

样例

样例输入 1

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

样例输出 1

2

样例输入 2

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

样例输出 2

2

样例输入 3

2 1
1 2

样例输出 3

1

样例输入 4

3 3
1 2
2 3
3 1

样例输出 4

0

样例输入 5

2 0

样例输出 5

2

样例输入 6

6 4
1 2
1 3
4 6
5 6

样例输出 6

3

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.