#K80587. Largest Strongly Connected Component
Largest Strongly Connected Component
Largest Strongly Connected Component
You are given a directed graph representing a network of towns and roads. There are n towns numbered from 1 to n and m directed roads, each road going from town a to town b.
Your task is to compute the size of the largest strongly connected component (SCC) in the graph. A strongly connected component is a maximal subset of towns such that for every pair of towns u and v in the subset, there exists a directed path from u to v and from v to u. In mathematical terms, you are to find:
$$\text{SCC size} = \max_{\text{component}}\{ |\text{component}| \}\n $$It is recommended to use Kosaraju's algorithm or any equivalent method to solve the problem efficiently.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer T, the number of test cases.
- For each test case:
- The first line contains two integers n and m where n is the number of towns and m is the number of roads.
- Then follow m lines, each containing two integers a and b representing a directed road from town a to town b.
outputFormat
For each test case, output a single integer on a separate line to stdout representing the size of the largest strongly connected component in the graph.
## sample1
5 5
1 2
2 3
3 1
4 5
5 4
3