Number of Connected Components

Medium

📝 Description

Count the number of connected components in an undirected graph

Input Format

Number of nodes and list of edges

Output Format

Number of components

Constraints

1 ≤ n ≤ 2000

🔍 Sample Input

5
[[0,1],[1,2],[3,4]]
            

✅ Sample Output

2
            

Code Editor

Please login to run and submit code.

Shortcuts: Ctrl+Enter to submit, Ctrl+Shift+R to run