#T33. 珍珠
珍珠
Description
There are n pearls that are identical in shape and size, but each has a unique weight. n is an integer, and all pearls are numbered from 1 to n. Your task is to determine which pearl's weight is exactly in the middle, i.e., the weight of this pearl ranks at the (n+1)/2 position among all pearl weights.
Here is the method for comparing a pair of pearls: You are given a balance scale to compare the weights of the pearls. We can determine which of the two pearls is heavier. After performing a series of comparisons, we can eliminate certain pearls that definitely do not have the median weight.
For example, consider the following four comparisons for five pearls:
- Pearl 2 is heavier than Pearl 1.
- Pearl 4 is heavier than Pearl 3.
- Pearl 5 is heavier than Pearl 1.
- Pearl 4 is heavier than Pearl 2.
Based on these results, although we cannot precisely identify which pearl has the median weight, we can conclude that Pearls 1 and 4 definitely do not have the median weight. This is because Pearls 2, 4, and 5 are heavier than Pearl 1, while Pearls 1, 2, and 3 are lighter than Pearl 4. Therefore, we can eliminate these two pearls.
Write a program to count how many pearls are definitely not of median weight.
Input Format
The first line contains two integers N and M separated by a space, where 1 ≤ N ≤ 99 and N is odd, and M represents the number of pearl comparisons. The following M lines each contain two integers x and y separated by a space, indicating that Pearl x is heavier than Pearl y.
Output Format
A single line containing an integer, representing the total number of pearls that cannot possibly have the median weight.
5 4
2 1
4 3
5 1
4 2
2