#P6282. [USACO20OPEN] Cereal S
[USACO20OPEN] Cereal S
Description
Farmer John’s cows’ favorite breakfast is, of course, cereal. In fact, the cows’ appetites are so large that each cow can eat a whole box of cereal in one meal.
Recently, the farm received a package containing different types of cereal (). Unfortunately, there is only one box of each type. Each of the cows () has a favorite cereal and a second favorite cereal. Given the available cereals, a cow will follow this process:
- If her favorite cereal is still available, she takes it and leaves.
- Otherwise, if her second favorite cereal is still available, she takes it and leaves.
- Otherwise, she moos in disappointment and leaves without taking any cereal.
The cows line up to take cereal. For each , determine how many cows will take a box of cereal if Farmer John removes the first cows from the line.
Input Format
The first line contains two space-separated integers and .
For each , the -th line contains two space-separated integers and (, and ), representing the favorite and second favorite cereals of the -th cow in the line.
Output Format
For each , output one line containing the answer for .
4 2
1 2
1 2
1 2
1 2
2
2
2
1
Hint
Sample Explanation
If at least two cows remain, then exactly two cows will take a box of cereal.
Subtasks
- Test cases - satisfy .
- Test cases - have no additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号