#C974. Largest Connected Component Sizes in Lake Graphs
Largest Connected Component Sizes in Lake Graphs
Largest Connected Component Sizes in Lake Graphs
You are given T lakes. Each lake is modeled as an undirected graph where nodes represent different fish types (numbered from 1 to \(N\)) and edges represent connections between these fish types.
Your task is to determine the size of the largest connected component for each lake. In other words, for each lake, find \(\max_{component}\,|component|\) where the components are the connected subgraphs.
You can solve the problem using graph traversal algorithms like Breadth-First Search (BFS) or Depth-First Search (DFS).
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer \(T\) representing the number of lakes.
- For each lake, the first line contains two integers \(N\) and \(M\):
- \(N\): the number of fish types (nodes).
- \(M\): the number of connections (edges).
- This is followed by \(M\) lines, each containing two integers \(u\) and \(v\) representing an undirected connection between fish types \(u\) and \(v\).
outputFormat
Output T integers separated by spaces on a single line. Each integer represents the size of the largest connected component for the corresponding lake.
## sample1
5 4
1 2
2 3
3 4
4 5
5
</p>