Under construction

Still being built. Things may change

Social Monsters

Time limit3sMemory limit512 MB

Summary
Choose K monsters maximizing total friendship, where given pairs have weight c (0 means the pair is forbidden) and all other pairs weigh 0. Each monster appears in at most two given pairs.
Level

Hard8 of 10

Topics
Graph, Dynamic programming, Greedy, Implementation
Solved
No attempts yet

Problem

There is a world where strange creatures and humans help each other and live together. In this world, tournaments where people pit the monsters they have caught against each other are held often, and many boys and girls aim to become the world's best trainer.

In a tournament, you build a party from the monsters you have caught and battle other parties. A pair of monsters has an affinity, which is either very bad or normal. If the affinity is very bad, the two monsters of that pair cannot be put in the same party. If the affinity is normal, the strength of the affinity is expressed by a number called friendship. In a battle, the sum of the friendship over the whole party decides the outcome.

Now you want to build a party of KK monsters out of NN monsters. The affinities of MM pairs of monsters (a_i, b_i)(a\_i, \, b\_i) are known, each given as an integer c_ic\_i. If c_i=0c\_i = 0, the a_ia\_i-th monster and the b_ib\_i-th monster have a very bad affinity. If c_i ≠ 0c\_i \, \neq \, 0, the a_ia\_i-th monster and the b_ib\_i-th monster have a normal affinity, and their friendship is c_ic\_i. For any pair other than the given MM pairs, the affinity is normal and the friendship is 00.

Think about how to choose the party so that the sum of friendship is as large as possible.

Input

The input is given in the following format.

NN MM KK

a_1a\_1 b_1b\_1 c_1c\_1

......

a_Ma\_M b_Mb\_M c_Mc\_M

Output

If a party of KK monsters cannot be built, output "Impossible" on one line.

If a party can be built, output the maximum sum of friendship.

Constraints

  • 1≤K≤N≤20001 ≤ K ≤ N ≤ 2000
  • 0≤M≤N0 ≤ M ≤ N
  • 1 ≤ a_i ≠ b_i ≤N1 \, ≤ \, a\_i \, \neq \, b\_i \, ≤ N
  • ∣c_i∣ ≤10000|c\_i| \, ≤ 10000
  • Each monster appears at most twice in a_1,a_2,…,a_M,b_1,b_2,…,b_Ma\_1, a\_2, …, a\_M, b\_1, b\_2, …, b\_M.
  • i ≠ j  ⇒  {a_i,b_i} ≠ {a_j, b_j}i \, \neq \, j \; ⇒ \; \{a\_i, b\_i\} \, \neq \, \{a\_j, \, b\_j\}

Examples3

  1. Example 1

    Input
    6 5 4
    2 1 1
    2 5 2
    5 1 1
    4 3 2
    3 6 -1
    
    Expected output
    4
    
  2. Example 2

    Input
    3 1 3
    1 2 -10
    
    Expected output
    -10
    
  3. Example 3

    Input
    6 3 5
    1 2 0
    2 3 10
    3 4 0
    
    Expected output
    Impossible