~/algor $ cat problems/minimal-qamrovchi-daraxt
Minimum spanning tree
A graph with $n$ vertices and $m$ undirected edges is given; each edge has a weight $w$. The vertices are numbered from $1$ to $n$. The minimum spanning tree of the graph is a set of edges connecting all vertices with the smallest total weight. Find this total. If the graph is not connected, print $-1$.
Input
The first line contains two integers: $n$ and $m$. Each of the next $m$ lines contains three integers: $u$, $v$ and $w$ — the vertices joined by the edge and the edge weight.
Output
One integer — the weight of the minimum spanning tree or $-1$.
Note
$1 \le n \le 10^{5}$
$0 \le m \le 2 * 10^{5}$
$1 \le u, v \le n$
$-10^{9} \le w \le 10^{9}$
Examples
4 5 1 2 1 1 3 4 2 3 2 2 4 5 3 4 3
6
3 1 1 2 5
-1