#C1636. Find Teams in a Friendship Graph

    ID: 44863 Type: Default 1000ms 256MiB

Find Teams in a Friendship Graph

Find Teams in a Friendship Graph

You are given a friendship graph with n employees and m friendships. Each friendship is represented as an undirected edge connecting two employees. A team is defined as a connected component in the graph.

Your task is to determine the number of teams. In mathematical terms, if the graph is represented as \(G=(V,E)\) where \(V\) is the set of vertices and \(E\) is the set of edges, then the number of teams equals the number of connected components in \(G\).

inputFormat

The input is given via stdin in the following format:

  1. The first line contains two space-separated integers \(n\) and \(m\) where \(1 \leq n \leq 10^5\) and \(0 \leq m \leq 10^5\), representing the number of employees and the number of friendships respectively.
  2. The following \(m\) lines each contain two integers \(a\) and \(b\) (\(1 \leq a, b \leq n\)), indicating that there is a friendship between employee \(a\) and employee \(b\).

outputFormat

Output a single integer to stdout representing the number of teams (i.e., the number of connected components in the graph).

## sample
6 5
1 2
2 3
4 5
5 6
6 4
2