QOJ.ac

QOJ

시간 제한: 5 s 메모리 제한: 1024 MB 총점: 100

#14891. Locking Doors

통계

只能从一侧锁门。

你刚刚在一家商场开始了一份新工作,不出所料,你分到了最糟糕的任务:晚上锁门歇业。商场由许多房间(可以是商店、走廊或其他公共空间)组成,房间之间有需要关闭的敞开的门。如果一扇门是开着的,你可以双向通过它;但令人烦恼的是,每扇门只能从它连接的两个房间中的其中一个进行锁定。

你的主管已经锁上了商场的主入口,并把你留在了里面,任务是锁上所有的门。为了做到这一点,你可以申请在某些房间中安装额外的出口。如果一个房间有出口,你就可以通过该房间进入或离开商场。

为了能够锁上所有的门并离开大楼,你最少需要申请安装多少个出口?

输入格式

输入包含:

  • 第一行包含两个整数 $n$ 和 $m$($2 \le n \le 10^5$,$1 \le m \le 10^6$),分别表示房间和门的数量。
  • 接下来 $m$ 行,每行包含两个不同的整数 $a$ 和 $b$($1 \le a, b \le n$,$a \ne b$),表示连接房间 $a$ 和 $b$ 的一扇门,且该门只能从房间 $a$ 锁定。

你可以假设所有有序对 $(a, b)$ 都是互不相同的,并且如果所有的门都打开,你可以从商场中的任何一个房间走到任何其他房间。

输出格式

输出需要安装的最小出口数量。

样例

输入样例 1

2 1
1 2

输出样例 1

1

输入样例 2

3 2
2 1
3 1

输出样例 2

2

输入样例 3

5 4
1 2
3 1
4 1
5 1

输出样例 3

3

输入样例 4

10 14
1 2
2 1
3 4
3 5
4 6
5 6
6 3
7 8
8 9
9 7
1 8
2 10
4 9
5 10

输出样例 4

2

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.