 All Problems
Count Unreachable Pairs of Nodes
medium
graphs
union find
dfs
amazon
google

You have n nodes (0-indexed) and undirected edges. Return the number of pairs of nodes that are unreachable from each other.

Example 1:

Input:
7 4
0 2
0 5
2 4
1 6
Output: 14

Input format: Line 1: n edges. Next edges lines: u v pairs.

Output format: Count of unreachable pairs.

Run to check your code against the sample cases, or submit to run every case