#C4250. Secret Communication Network
Secret Communication Network
Secret Communication Network
You are given a network of P people numbered from 1 to P. Initially, only person 1 knows a secret. When two people communicate, if at least one of them knows the secret, then after the communication both will know the secret. In other words, the secret spreads along the connected components of the network. Your task is to determine the number of people who will know the secret after all the communications have taken place.
Mathematically, if we consider an undirected graph where each person represents a node and each communication is an edge, then the answer is the size of the connected component that contains node 1. That is, if we let \(G=(V,E)\) be the graph and \(v_1=1\), you need to compute the number of vertices in the set \(\{ v: v \text{ is reachable from } v_1 \}\).
inputFormat
The first line contains two integers P and C, where P is the total number of people and C is the number of communications. Each of the following C lines contains two space-separated integers a and b, representing a communication between person a and person b.
outputFormat
Output a single integer: the number of people who know the secret after all communications.
## sample3 2
1 2
2 3
3