Phone Plans

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

The mayor of CCOland, Jason, wants to install telephone lines amongst NN households, which are numbered from 11 to NN. To do so, he has asked two rivalling companies, Keenan Mobile Phones and Chris Home Telephone, for their phone plans. A phone plan for a company corresponds to a certain level, and every telephone line has a level and company associated with it. If you have purchased a phone plan from a company with level ll, then you are able to use all the telephone lines whose level is less than or equal to ll that is associated with that company. A phone plan of level ll costs \\l,andyoucannotpickaphoneplanoflessthan, and you cannot pick a phone plan of less than \00.

Two households can only communicate with each other if they are connected by a path of telephone lines of the same company. Jason would like to buy one phone plan from each company of minimal cost such that there are at least KK different pairs of households that can communicate with each other.

입력

The first line contains four space-separated integers NN, AA, BB, and KK, which represent the number of households, number of telephone lines from Keenan Mobile Phones, number of telephone lines from Chris Home Telephone and the minimum pairs of homes that need to be able to communicate with each other, respectively.

The next AA lines each contain three space-separated integers uu, vv, and ll, which represent a Keenan Mobile Phones telephone line between household uu and vv (1u,vN)(1 \le u, v \le N) that has a level ll (1l109)(1 \le l \le 10^9).

The next BB lines have the same format as the previous AA lines but for Chris Home Telephone.

출력

Output the cheapest cost needed to connect at least KK different pairs of households or −1 if it is not possible.

힌트

For each company, consider these pictures of the way the 66 households are connected by telephone lines:

(Note that the diagram is unavailable tentatively.)

If Jason buys phone plan level 33 from Keenan Mobile Phones and phone plan level 3030 from Chris Home Telephone, then (1,2),(1,3),(1,4),(2,3),(2,4),(3,4)(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4) can communicate through Keenan Mobile Phones' lines and (1,5),(2,6),(3,6),(2,3)(1, 5), (2, 6), (3, 6), (2, 3) can communicate through Chris Home Telephone's lines. There are no cheaper ways.