Logo
(追記) (追記ここまで)

33226번 - Highways of the Future 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
6 초 2048 MB87583.333%

문제

Midgard is a city of mana energy and center of the world's economy. With its development steered by President Shinda, chair of the Shinda electric power company, the great city has undergone an age of great prosperity. Recently, however, there have been reports that a group of bandits called Snowfall has been attacking and shutting down its mana reactors. In preparation for another attack, President Shinda has assigned you the role of chief engineer in a restructuring plan.

The city consists of $n$ sectors, each of which has a mana reactor: an enormous facility which extracts energy from deep within the earth and transforms it into electricity powering the whole sector. Currently, there are $m$ highways between sectors. Each highway can be used to transport electric power from sector to sector and has only one direction. The president has instructed you to build new highways between sectors, such that no matter which reactors get shut down, the entire city will still have electrical power as long as there is at least 1ドル$ reactor functioning.

Each reactor has an unlimited capacity for mana energy and can supply any number of sectors as long as it is directly or indirectly connected to them. Additionally, due to the sheer cost of building a highway, the president has instructed you to build as few highways as possible, while still satisfying his previous condition.

입력

The input consists of:

  • A line containing two integers $n$ (1ドル\leq n\leq 10^5$) and $m$ (0ドル\leq m\leq 2\cdot 10^5$), representing the number of sectors in Midgard and the number of existing highways, respectively.
  • Then follow $m$ lines containing two integers each, $x$ and $y$ (1ドル \leq x,y \leq n$), which indicate the presence of a one-directional highway from sector $x$ to sector $y$.

출력

Output the minimum number of highways that have to be added to have any reactor be able to power every sector.

제한

예제 입력 1

3 2
1 2
1 3

예제 출력 1

2

예제 입력 2

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

예제 출력 2

3

예제 입력 3

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

예제 출력 3

3

힌트

출처

University > Delft University of Technology > Freshmen Programming Contest 2022 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /