AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

FPC22-026.Highways of the Future

Easy · 5 s · 256 MB

  • icpc
  • fpc
  • 2022

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 nnn 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 mmm 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 111 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.

Giriş formatı

The input consists of:

• A line containing two integers nnn (1≤n≤1051\leq n\leq 10^51≤n≤105) and mmm (0≤m≤2⋅1050\leq m\leq 2\cdot 10^50≤m≤2⋅105), representing the number of sectors in Midgard and the number of existing highways, respectively.

• Then follow mmm lines containing two integers each, xxx and yyy (1≤x,y≤n1 \leq x,y \leq n1≤x,y≤n), which indicate the presence of a one-directional highway from sector xxx to sector yyy.

Çıxış formatı

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

Qeyd

Source: Freshmen Programming Contest 2022 · Author: Cristian-Alexandru Botocan · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license. · 5 of the 20 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

3 2
1 2
1 3

Çıxış #1

2

Giriş #2

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

Çıxış #2

3

Giriş #3

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

Çıxış #3

3