题目描述
Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk producer to the slowest.
农夫约翰有N(1 ≤ N ≤ 1,000)头奶牛,每一头奶牛都有一个确定的独一无二的正整数产奶率,约翰想要让这些奶牛按产奶率从高到低排序。
FJ has already compared the milk output rate for M (1 ≤ M ≤ 10,000) pairs of cows. He wants to make a list of C additional pairs of cows such that, if he now compares those C pairs, he will definitely be able to deduce the correct ordering of all N cows. Please help him determine the minimum value of C for which such a list is possible.
约翰已经比较了M(1 ≤ M ≤ 10,000)对奶牛的产奶率,但他发现,他还需要再做一张关于另外C对奶牛的产奶率比较,才能推断出所有奶牛的产奶率排序,请帮他确定C的最小值。
输入格式:
Line 1: Two space-separated integers: N and M
Lines 2..M+1: Two space-separated integers, respectively: X and Y. Both X and Y are in the range 1...N and describe a comparison where cow X was ranked higher than cow Y.
第1行包含两个用空格分开的正整数N和M,接下来M行,每行有两个用空格分开的整数X和Y(1 ≤ X,Y ≤ 1,000),表示奶牛X的产奶率高于奶牛Y。
输出格式:
Line 1: A single integer that is the minimum value of C.
一行:C的最小值。
输入样例#1:
5 5
2 1
1 5
2 3
1 4
3 4
输出样例#1:
3