You have a graph of n nodes labeled from 0 to n - 1. Given an integer n and a list of edges where edges[i] = [a_i, b_i] indicates an undirected edge between node a_i and node b_i, return the number of connected components in the graph.
0 --- 1 --- 2 3 --- 4
Input: n = 5, edges = [[0, 1], [1, 2], [3, 4]] Output: 2 Explanation: Nodes 0, 1, 2 form one component. Nodes 3, 4 form a second.
0 --- 1 --- 2 --- 3 --- 4
Input: n = 5, edges = [[0, 1], [1, 2], [2, 3], [3, 4]] Output: 1 Explanation: All five nodes are connected in a single chain.
Input: n = 5, edges = [] Output: 5 Explanation: No edges means every node is its own isolated component.
1 <= n <= 20000 <= edges.length <= 5000edges[i].length == 20 <= a_i, b_i < na_i != b_in = 5, edges = [[0, 1], [1, 2], [3, 4]]