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

    ID: 16786 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>2017网络流二分图ICPCDilworth 定理

[ICPC 2017 Nanning R] The Maximum Unreachable Node Set

题目描述

In this problem, we would like to talk about unreachable sets of a directed acyclic graph G=(V,E)G = (V,E). In mathematics a directed acyclic graph (DAG)(DAG) 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 EE that eventually loops back to the beginning again.

A node set denoted by VUR⊂VV_{UR} \subset V containing several nodes is known as an unreachable node set of GG if, for each two different nodes uu and vv in VURV_{UR}, there is no way to start at uu and follow a consistently-directed sequence of edges in EE that finally archives the node vv. You are asked in this problem to calculate the size of the maximum unreachable node set of a given graph GG.

输入格式

The input contains several test cases and the first line contains an integer T(1≤T≤500)T (1 \le T \le 500) which is the number of test cases.

For each case, the first line contains two integers n(1≤n≤100)n (1 \le n \le 100) and m(0≤m≤n(n−1)/2)m (0 \le m \le n(n - 1)/2) indicating the number of nodes and the number of edges in the graph GG. Each of the following mm lines describes a directed edge with two integers uu and v(1≤u,v≤nv (1 \le u, v \le n and u≠v)u \neq v) indicating an edge from the uu-th node to the vv-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 mm in input is smaller than 500000500000.

输出格式

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

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
2
1
3