#C8745. Minimum Cost to Connect All Points
Minimum Cost to Connect All Points
Minimum Cost to Connect All Points
In this problem, you are given a complete weighted graph represented by an n×n cost matrix. Your task is to find the minimum cost required to connect all points (i.e., the minimum spanning tree cost). Formally, given an integer and a cost matrix , where represents the cost to connect point and point , find the minimum total cost such that all points become connected.
One efficient solution uses Prim's algorithm.
Formally, you are to compute $$\min\sum_{(u,v)\in T}C[u][v],$$ where is a spanning tree of the complete graph with vertices .
inputFormat
The input is read from standard input (stdin) and has the following format:
First line: a single integer denoting the number of points.
Next lines: each line contains space-separated integers representing the cost matrix. The -th integer in the -th line denotes .
outputFormat
Output to standard output (stdout) a single integer that is the minimum cost to connect all points.## sample
3
0 1 2
1 0 3
2 3 0
3