#P2273. [HNOI2002] 交换
[HNOI2002] 交换
Description
Given integer registers . We define a compare-exchange instruction as follows: if the value in is greater than the value in , then swap the values in registers and . Here, .
A compare-exchange program (abbreviated as a CE program) is a finite sequence of compare-exchange instructions. A CE program is called a MIN program if, after executing the program, the value in register is the minimum among all registers. If a CE program remains a MIN program after removing any single instruction from it, then the CE program is called a reliable MIN program.
Your task is: given a CE program , compute the minimum number of instructions that must be appended to the end of to make a reliable MIN program.
For example, consider the following CE program on three registers:
, , .
We only need to append two instructions: , to make this CE program a reliable MIN program.
Input Format
There are two lines. The first line contains two space-separated integers and ; here is the number of registers (), and is the number of instructions in the CE program ().
The second line contains instructions . Inside each instruction, and are separated by a comma, and different instructions are also separated by commas.
Output Format
Output a single integer on one line: the minimal number of instructions that should be appended.
3 3
1,2,2,3,1,2
2
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号