#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 MM different types of cereal (1M1051\le M\le 10^5). Unfortunately, there is only one box of each type. Each of the NN cows (1N1051\le N\le 10^5) 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 0iN10\le i\le N-1, determine how many cows will take a box of cereal if Farmer John removes the first ii cows from the line.

Input Format

The first line contains two space-separated integers NN and MM.

For each 1iN1\le i\le N, the ii-th line contains two space-separated integers fif_i and sis_i (1fi,siM1\le f_i,s_i\le M, and fisif_i\neq s_i), representing the favorite and second favorite cereals of the ii-th cow in the line.

Output Format

For each 0iN10\le i\le N-1, output one line containing the answer for ii.

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 22-33 satisfy N,M103N,M\le 10^3.
  • Test cases 44-1010 have no additional constraints.

Translated by ChatGPT 5