|
<p> |
|
With a successful commission under his belt, Carlos has really made a splash |
|
with his consulting firm, Carlos Structures Industries. His next customer is |
|
Texas Instruments, the well-known manufacturer of graphing calculators. |
|
</p> |
|
|
|
<p> |
|
<em> |
|
"In today's competitive environment, you need an edge. I can make sure that |
|
your newest graphing calculator is chock-full of the best modern graphs." |
|
</em> |
|
</p> |
|
|
|
<p> |
|
Carlos's pitch seems to have worked as Texas Instruments has ordered an |
|
undirected, weighted graph. Their R&D department has come up with a list |
|
of requirements that will ensure the graph is a hit with Gen Z schoolchildren. |
|
</p> |
|
|
|
<p> |
|
To start with, the graph must have <strong>N</strong> nodes numbered 1 to <strong>N</strong>. It must have no |
|
self-loops and at most one edge connecting each unordered pair of nodes. The |
|
weight of each edge must be an integer between 1 and 1,000,000, inclusive. |
|
The graph does not need to be connected. |
|
</p> |
|
|
|
<p> |
|
The graph must also satisfy <strong>M</strong> customer requirements, the <em>i</em>th of which states |
|
that the shortest distance between two different nodes <strong>X<sub>i</sub></strong> and <strong>Y<sub>i</sub></strong> must be equal to <strong>Z<sub>i</sub></strong>. |
|
No two requirements pertain to the same unordered pair of nodes. |
|
</p> |
|
|
|
<p> |
|
Carlos's goal is to find any valid graph consistent with all of these requirements |
|
if possible, or to determine that no such graph exists. |
|
</p> |
|
|
|
|
|
|
|
<h3>Input</h3> |
|
|
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of graphs that Texas Instruments has commissioned. |
|
For each graph, there is first a line containing the space-separated integers <strong>N</strong> and <strong>M</strong>. |
|
Then, <strong>M</strong> lines follow, the <em>i</em>th of which contains the space-separated integers |
|
<strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong>, and <strong>Z<sub>i</sub></strong>. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
|
|
<p> |
|
For the <em>i</em>th graph, print a line containing "Case #<em>i</em>: " |
|
followed by either an integer <strong>E</strong> and then a description of a valid graph if possible, or the string "Impossible" if no valid graph exists. |
|
</p> |
|
|
|
<p> |
|
A graph description contains <strong>E</strong> lines, where <strong>E</strong> is the number of edges in your graph. |
|
The <em>i</em>th line contains the space-separated integers |
|
<strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong>, and <strong>W<sub>i</sub></strong> |
|
indicating that there is an edge between nodes <strong>A<sub>i</sub></strong> and <strong>B<sub>i</sub></strong> with weight <strong>W<sub>i</sub></strong>. |
|
Please keep in mind that your graph must satisfy all of the requirements stated above (both the fundamental requirements dictated by Texas Instruments, and the <strong>M</strong> customer ones). |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
|
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 350 <br /> |
|
2 ≤ <strong>N</strong> ≤ 50 <br /> |
|
1 ≤ <strong>M</strong> ≤ 1,000 <br /> |
|
1 ≤ <strong>X<sub>i</sub></strong>, <strong>Y<sub>i</sub></strong> ≤ <strong>N</strong> <br /> |
|
<strong>X<sub>i</sub></strong> ≠ <strong>Y<sub>i</sub></strong> <br /> |
|
1 ≤ <strong>Z<sub>i</sub></strong> ≤ 1,000,000 <br /> |
|
</p> |
|
|
|
<h3>Explanation of Sample</h3> |
|
|
|
<p> |
|
In the graph described by the first sample case's sample output, the shortest distance between nodes 3 and 1 is 5 (along the path 3 -> 2 -> 1), as required. <b>Multiple other outputs would also be accepted for this case.</b> |
|
</p> |
|
|
|
<p> |
|
<b>Multiple other outputs would also be accepted for the third and fourth cases.</b> |
|
</p> |
|
|
|
|