## Summer Institute '17 Contest 1 P1 - Ant Clans

View as PDF

Points: 20 (partial)
Time limit: 1.4s
C 0.75s
C++ 0.75s
Memory limit: 256M

Problem types
##### Summer Institute @ University of Central Florida: Contest 1, Problem 1

An ant dynasty has decided to move into a giant ant hill consisting of burrows. The dynasty has a complicated social structure formed by a coalition of ant clans, where each clan doesn't get along well with the others. To keep the peace, the ant emperor wants to partition all burrows into equally-sized districts (one per clan), so that no ant from any clan should be able to reach any ant of an opposing clan. After deciding on the districts, the ants will drill tunnels between certain carefully chosen pairs of burrows so ants in each clan can travel among all the burrows allocated to the district for the clan. The ant emperor would like to know the cheapest cost possible for forming his districts and building the resulting tunnels.

#### Input Specification

The first line of input contains 3 space separated integers: , and , representing the number of burrows, number of possible tunnels that can be drilled, and the number of districts to form. Burrows are labeled with identifiers .

This is followed by lines each containing 3 space separated integers: , , and meaning that the burrow labeled can be connected by a tunnel to the burrow labeled with cost .

#### Output Specification

On a line by itself, print the minimum cost possible of the desired partition, or -1 if such a district plan is impossible.

#### Sample Input 1

4 4 2
1 2 300
2 3 200
3 4 100
4 1 8

#### Sample Output 1

208

#### Sample Input 2

6 4 3
1 2 3
2 3 4
4 5 6
5 6 7

#### Sample Output 2

-1

Original Problem Author: [email protected]