Skip to content
We areTOP 1%

Min Cost to Connect All Points

MediumLeetCodeGraph Theory (MST, SCC, Bridges)
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

The graph is complete, so Prim's algorithm with a plain distance array runs in O(n^2) without materialising every edge. Kruskal with a DSU over all pairs also passes.

More in Graph Theory (MST, SCC, Bridges)

Graph Theory (MST, SCC, Bridges) questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Min Cost to Connect All PointsLeetCodeMedium Solve Min Cost to Connect All Points on LeetCode (opens in a new tab)
2CheckpostsCodeforcesMedium 1700Solve Checkposts on Codeforces (opens in a new tab)
3Critical Connections in a NetworkLeetCodeHard Solve Critical Connections in a Network on LeetCode (opens in a new tab)
40-1 MSTCodeforcesHard 1900Solve 0-1 MST on Codeforces (opens in a new tab)
5MinOr TreeCodeforcesHard 1900Solve MinOr Tree on Codeforces (opens in a new tab)
6Make It ConnectedCodeforcesHard 1900Solve Make It Connected on Codeforces (opens in a new tab)
7Find Critical and Pseudo-Critical Edges in Minimum Spanning TreeLeetCodeHard Solve Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree on LeetCode (opens in a new tab)
8Valid Arrangement of PairsLeetCodeHard Solve Valid Arrangement of Pairs on LeetCode (opens in a new tab)
9Bertown roadsCodeforcesHard 2000Solve Bertown roads on Codeforces (opens in a new tab)
10Reachability from the CapitalCodeforcesHard 2000Solve Reachability from the Capital on Codeforces (opens in a new tab)
11We Need More BossesCodeforcesHard 2100Solve We Need More Bosses on Codeforces (opens in a new tab)
12Minimum spanning tree for each edgeCodeforcesHard 2100Solve Minimum spanning tree for each edge on Codeforces (opens in a new tab)
13Edges in MSTCodeforcesHard 2300Solve Edges in MST on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account