⬅ Previous TopicKruskal's Algorithm - Minimum Spanning Tree
Next Topic ⮕Most Stones Removed with Same Row or Column
You are given a network of n
computers numbered from 0
to n-1
, connected by a list of m
edges. Each edge connects two computers directly. In one operation, you can remove any existing edge and reconnect it between any two disconnected computers.
Your task is to determine the minimum number of such operations required to ensure that all computers are directly or indirectly connected. If it is not possible to connect the entire network, return -1
.