Number of Operations to Make Network Connected
Medium
Graph Algorithms (Advanced)
There are n computers and a list of cables between them. In one operation you can move any cable to connect two computers that are not directly connected. Print the minimum number of operations to connect all computers, or -1 if there are not enough cables.
Constraints
1 <= n <= 10^5 0 <= m <= 10^5
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.