Problems
The mayor of CCOland, Jason, wants to install telephone lines amongst
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
Input
The first line contains four space-separated integers
The next
The next
Output
Output the cheapest cost needed to connect at least −1 if it is not possible.
Subtask
| # | Score | Condition |
|---|---|---|
| #1 | 24 | |
| #2 | 20 | Keenan Mobile Phones only connects to odd indexed households; Chris Home Telephone only connects to even indexed households |
| #3 | 24 | |
| #4 | 32 | |
Example
6 4 4 9
1 2 1
2 3 2
1 4 3
3 4 4
5 6 40
1 5 30
2 6 20
3 6 10
33
For each company, consider these pictures of the way the
(Note that the diagram is unavailable tentatively.)
If Jason buys phone plan level