Union-Find

Maximal Network Connectivity

January 8, 2024
medium
Union-Find

Problem # Given a network of n cities and a list of roads connecting these cities, find the maximum number of cities that can be connected directly or indirectly via these roads. You can assume that the roads are bidirectional and that each pair of cities has at most one direct road connecting them. Example: # Input: n = 4, roads = [[0, 1], [0, 2], [1, 2], [1, 3]] Output: 4 Explanation: All cities can be connected directly or indirectly by the given roads. ...