logo AlgoBeat OnlineJudge
登录 注册

#217131. [ICPC 2017 Nanning R] The Maximum Unreachable Node Set

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

In this problem, we would like to talk about unreachable sets of a directed acyclic graph . In mathematics a directed acyclic graph is a directed graph with no directed cycles. That is a graph such that there is no way to start at any node and follow a consistently-directed sequence of edges in that eventually loops back to the beginning again.

A node set denoted by containing several nodes is known as an unreachable node set of if, for each two different nodes and in , there is no way to start at and follow a consistently-directed sequence of edges in that finally archives the node . You are asked in this problem to calculate the size of the maximum unreachable node set of a given graph .

输入格式

The input contains several test cases and the first line contains an integer which is the number of test cases.

For each case, the first line contains two integers and indicating the number of nodes and the number of edges in the graph . Each of the following lines describes a directed edge with two integers and and indicating an edge from the -th node to the -th node. All edges provided in this case are distinct.

We guarantee that all directed graphs given in input are DAGs and the sum of in input is smaller than .

输出格式

For each test case, output an integer in a line which is the size of the maximum unreachable node set of .

样例

样例输入 1

3
4 4
1 2
1 3 
2 4
3 4
4 3
1 2
2 3
3 4
6 5
1 2
4 2
6 2
2 3
2 5

样例输出 1

2
1
3