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

FPC23-008.Hunting the Mavericks

Easy · 3 s · 256 MB

  • icpc
  • fpc
  • 2023

The year is 21XX, and finally, after a century of patiently waiting, you are excited to play the new Mega Man X game on your Xbox 1024. As usual, there are nnn levels, numbered 111 to nnn, each of which ends with a fight against a corrupted robot known as a Maverick. Upon defeating a Maverick, you are able to use its weapon throughout the rest of the game. Every Maverick is weak to the weapon you find in the previous level numerically (the Maverick in level 222 is only weak to the weapon in level 111, and the Maverick in level nnn is weak to the weapon in level n−1n - 1n−1). The only exception to this is that the Maverick in level 111 is weak to the weapon in level nnn.

Additionally, some levels contain one or more armour upgrades, with there being mmm armour upgrades in total. Every armour upgrade iii requires the weapon in level wiw_iwi​ to be unlocked and can be found in level lil_ili​, where wi≠liw_i \neq l_iwi​=li​. In one run through a level, you can collect any number of armour upgrades, as long as you have the weapons that unlock them.

You really hate backtracking, so you will only go through each level once, leaving behind any armour upgrade you cannot obtain immediately. In order to make the game easier, you decide that will do the levels in an order where you only pick levels where the Maverick is weak to to a weapon you have. You can pick any level to start with, you don't require to have the weakness weapon yet. After picking the starting level, you will finish the levels in order (going from level nnn to level 111 still counts as in order) until you have beaten all levels exactly once. The problem with your approach is that it misses potentially a lot of armour upgrades, which is not good considering the final boss is very tough. Since you want to beat the game as efficiently as possible, you decide to write a program that determines the minimum number of armour upgrades you will have to miss.

Giriş formatı

The input consists of:

• A line with two integers nnn and mmm (2≤n≤1052 \leq n \leq 10^52≤n≤105, 1≤m≤1051 \leq m \leq 10^51≤m≤105), the number of levels in the game and the number of armour upgrades.

• mmm lines, containing two integers wiw_iwi​ and lil_ili​ (1≤wi,li≤n1 \leq w_i, l_i \leq n1≤wi​,li​≤n, wi≠liw_i \neq l_iwi​=li​), the level in which the weapon needed to unlock armour upgrade iii is, and the level containing armour upgrade iii.

Çıxış formatı

Output the minimum number of armour upgrades you will miss.

Qeyd

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

Nümunələr

Giriş #1

4 3
1 3
4 3
2 4

Çıxış #1

1

Giriş #2

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

Çıxış #2

2