| <p> |
|
|
| You're throwing a party for your friends, but since your friends may not all |
| know each other, you're afraid a few of them may not enjoy your party. So to |
| avoid this situation, you decide that you'll also invite some friends of your |
| friends. But who should you invite to throw a great party? |
|
|
| </p> |
|
|
| <p> |
|
|
| Luckily, you are in possession of data about all the friendships of your friends |
| and their friends. In graph theory terminology, you have a subset |
| <strong>G</strong> of the social graph, whose vertices correspond to your |
| friends and their friends (excluding yourself), and edges in this graph denote |
| mutual friendships. Furthermore, you have managed to obtain exact estimates |
| of how much food each person in <strong>G</strong> will consume during the |
| party if he were to be invited. |
|
|
| </p> |
|
|
| <p> |
|
|
| You want to choose a set of guests from <strong>G</strong>. This set of guests |
| should include all your friends, and the subgraph of <strong>G</strong> formed |
| by the guests must be connected. You believe that this will ensure that all of |
| your friends will enjoy your party since any two of them will have something to |
| talk about... |
|
|
| </p> |
|
|
| <p> |
|
|
| In order to save money, you want to pick the set of guests so that the total |
| amount of food needed is as small as possible. If there are several ways of |
| doing this, you prefer one with the fewest number of guests. |
|
|
| </p> |
|
|
| <p> |
|
|
| The people/vertices in your subset <strong>G</strong> of the social graph are |
| numbered from 0 to <strong>N</strong> - 1. Also, for convenience your friends |
| are numbered from 0 to <strong>F</strong> - 1, where <strong>F</strong> is the |
| number of your friends that you want to invite. You may also assume that |
| <strong>G</strong> is connected. Note again that you are not |
| yourself represented in <strong>G</strong>. |
|
|
| </p> |
|
|
| <h2>Input</h2> |
|
|
|
|
| The first line of the input consists of a single number <strong>T</strong>, the |
| number of test cases. Each test case starts with a line containing three |
| integers <strong>N</strong>, the number of nodes in <strong>G</strong>, |
| <strong>F</strong>, the number of friends, and <strong>M</strong>, the number of |
| edges in <strong>G</strong>. This is followed by <strong>M</strong> lines each |
| containing two integers. The <strong>i</strong><sup>th</sup> of these lines will contain |
| two distinct integers <strong>u</strong> and <strong>v</strong> which indicates |
| a mutual friendship between person <strong>u</strong> and person |
| <strong>v</strong>. After this follows a single line containing |
| <strong>N</strong> space-separated integers with the <strong>i</strong><sup>th</sup> |
| representing the amount of food consumed by person <strong>i</strong>. |
| <br/> |
| <br/> |
|
|
|
|
| <h2>Output</h2> |
| Output <strong>T</strong> lines, with the answer to each test case on a single |
| line by itself. Each line should contain two numbers, the first being the minimum total |
| quantity of food consumed at a party satisfying the given criteria and the |
| second the minimum number of people you can have at such a party. |
| <br/> |
| <br/> |
|
|
| <h2>Constraints</h2> |
| <strong>T</strong> = 50<br/> |
| 1 ≤ <strong>F</strong> ≤ 11<br/> |
| <strong>F</strong> ≤ <strong>N</strong>-1 <br/> |
| 2 ≤ <strong>N</strong> ≤ 250<br/> |
| <strong>N</strong>-1 ≤ <strong>M</strong> ≤ <strong>N</strong> * (<strong>N</strong> - 1) / 2<br/> |
| <strong>G</strong> is connected, and contains no self-loops or duplicate edges.<br/> |
| For each person, the amount of food consumed is an integer between 0 and 1000, both inclusive. |
|
|