2563. Dominos

单点时限: 5.0 sec

内存限制: 256 MB

Dominos are lots of fun. Children like to stand the tiles on their side in long lines. When one domino falls, it knocks down the next one, which knocks down the one after that, all the way down the line. However, sometimes a domino fails to knock the next one down. In that case, we have to knock it down by hand to get the dominos falling again.

Your task is to determine, given the layout of some domino tiles, the minimum number of dominos that must be knocked down by hand in order for all of the dominos to fall.

输入格式

The first line of input contains one integer specifying the number of test cases to follow. Each test case begins with a line containing two integers, each no larger than 100 000. The first integer n is the number of domino tiles and the second integer m is the number of lines to follow in the test case. The domino tiles are numbered from 1 to n. Each of the following lines contains two integers x and y indicating that if domino number x falls, it will cause domino number y to fall as well.

输出格式

For each test case, output a line containing one integer, the minimum number of dominos that must be knocked over by hand in order for all the dominos to fall.

样例

Input
1
3 2
1 2
2 3
Output
1

13 人解决,42 人已尝试。

36 份提交通过,共有 217 份提交。

7.3 EMB 奖励。

创建: 15 年,7 月前.

修改: 7 年,2 月前.

最后提交: 4 年,10 月前.

来源: Waterloo local 2008

题目标签