#C3196. Largest Connected Component in a Network
Largest Connected Component in a Network
Largest Connected Component in a Network
You are given a network of devices. Each device is represented as a node and each connection between two devices is represented as an edge. Your task is to determine the size of the largest group of connected devices in the network. Two devices are connected if there is a path between them. The network may contain self-loops and multiple disconnected components.
Formally, given a list of m edges, where each edge connects two nodes (devices), find the maximum number of nodes in any connected component. The connectivity is defined in the usual way: a set of nodes is connected if for every pair of nodes in the set, there is a path in the induced subgraph.
The mathematical definition of the size of a connected component can be written as:
[ CC = \max_{i} { |C_i| : C_i \text{ is a connected component of the graph} } ]
If the network is empty, output 0.
inputFormat
The input is given via standard input (stdin) and has the following format:
m u1 v1 nu2 v2 ... num vm
Here, m
is the number of edges. Each of the following m
lines contains two space-separated integers representing a connection between two devices. The integers represent node labels and may include self-loops (u = v).
outputFormat
Output a single integer (written to standard output, stdout) which is the size of the largest connected component in the network.
## sample6
1 2
2 3
3 4
5 6
6 7
8 8
4