#C2961. Distinct Bird Populations

    ID: 46335 Type: Default 1000ms 256MiB

Distinct Bird Populations

Distinct Bird Populations

In a sprawling park divided into n sections, each pair of sections may be connected by bidirectional trails. Birds tend to form populations that reside in connected sections. Given the total number of sections n, the number of trails m, the list of trails connecting the sections, and a starting section s, your task is to determine the number of distinct sections (or bird populations) that are reachable from section s using the available trails.

The connections between sections form an undirected graph, and you need to compute the size of the connected component containing s. The input is read from the standard input (stdin) and the output should be printed to the standard output (stdout).

inputFormat

The input consists of multiple lines:

  • The first line contains two integers n and m — the number of sections and the number of trails, respectively.
  • The next m lines each contain two integers u and v indicating there is a bidirectional trail between sections u and v.
  • The last line contains a single integer s, the starting section.

outputFormat

Output a single integer representing the number of sections in the connected component that can be reached from section s.

## sample
4 3
1 2
2 3
3 4
1
4

</p>