C. Prim's Problem
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
3 2
1 2 10
1 3 100
Output
0
Input
3 2
1 2 10
2 3 30
Output
-1
Input
3 3
1 2 10
1 3 100
2 3 30
Output
1