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 levels, numbered to , 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 is only weak to the weapon in level , and the Maverick in level is weak to the weapon in level ). The only exception to this is that the Maverick in level is weak to the weapon in level .
Additionally, some levels contain one or more armour upgrades, with there being armour upgrades in total. Every armour upgrade requires the weapon in level to be unlocked and can be found in level , where . 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 to level 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 and (, ), the number of levels in the game and the number of armour upgrades.
• lines, containing two integers and (, ), the level in which the weapon needed to unlock armour upgrade is, and the level containing armour upgrade .
Çı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