Mandark's Clique Problem

0

0 votes
Hard
Problem

Mandark has always been one step behind Dexter and has done all he can to get the better of his rival and prove once and for all that he is the superior boy genius, but every time he tries to, he always ends up failing horribly. 

But this time he has challenged Dexter in graph theory to prove his brilliance.
He has given a problem to Dexter, which he has to solve in order to defeat Mandark.

The Problem:
A directed graph G is given.
An auxiliary graph has to be created from the given directed graph.
The auxiliary graph has the same vertices as the original graph.
There is a directed edge between two vertices u and v in the auxiliary graph iff there is a path between u and v in the original graph G that follows directed edges only in the forward direction.
Dexter's task is to find the largest clique in the auxiliary graph

A clique in a directed graph is defined as a set of vertices X such that for any two vertices a and b in X there is a directed edge from a to b or from b to a or both. 
Size of the clique is the number of vertices in it.

INPUT
The first line contains an integer T, denoting the number of test cases.
The first line of each test case contains two integers n and m, where n represents the number of vertices and m represents the number of directed edges in the graph
The next m lines contain two distinct integers u and v which defines a directed edge from u to v.

OUTPUT
For each test case output a single integer denoting the size of the largest clique in the auxiliary graph.

CONSTRAINTS

1 <= <= 10
0 <= n <= 1000
0 <= m <= 50000
The vertices are numbered from 1 to n

Time Limit: 3
Memory Limit: 256
Source Limit:
Editor Image

?