|
<p> |
|
Ethan is doing his third programming assignment: finding the shortest path between two nodes in a graph. |
|
</p> |
|
|
|
<p> |
|
Given an undirected, weighted graph with <strong>N</strong> nodes (numbered from 1 to <strong>N</strong>), having no self-loops or duplicate edges, |
|
Ethan must compute the length of the shortest path from node 1 to node <strong>N</strong>. Ethan has implemented an algorithm to solve this problem, described by the following pseudocode: |
|
</p> |
|
|
|
<ol> |
|
<li>Set <em>i</em> to be equal to 1, and <em>d</em> to be equal to 0</li> |
|
<li>If <em>i</em> is equal to <strong>N</strong>, output <em>d</em> and stop</li> |
|
<li>Find the edge incident to node <em>i</em> that has the smallest weight |
|
(if no edges are incident to <em>i</em> or if there are multiple such edges tied with the smallest weight, then crash instead)</li> |
|
<li>Increase <em>d</em> by the weight of this edge, and set <em>i</em> to be equal to the other node incident to this edge</li> |
|
<li>Return to Step 2</li> |
|
</ol> |
|
|
|
<p> |
|
Since you were nice to Ethan on his second assignment, and since that encouragement clearly hasn't helped improve the quality of his code, you'd like to find a graph that shows as clearly as |
|
possible why this solution is incorrect. |
|
</p> |
|
|
|
<p> |
|
You're given the number of nodes in the graph <strong>N</strong>, as well as the maximum allowable edge weight <strong>K</strong> |
|
(each edge's weight must be an integer in the interval [1, <strong>K</strong>]). |
|
Under these constraints you want to maximize the absolute difference between Ethan's output and the actual shortest distance between nodes 1 and <strong>N</strong>. |
|
However, you don't want Ethan's algorithm to either crash or run forever. |
|
Note that node <strong>N</strong> must actually be reachable from node 1 in the graph, though the graph may be otherwise disconnected. |
|
You can output any valid graph which gets the job done. |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
|
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of graphs. |
|
For each graph, there is a line containing the space-separated integers <strong>N</strong> and <strong>K</strong>. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
|
|
<p> |
|
For the <em>i</em>th graph, first output a line containing "Case #<em>i</em>: " |
|
followed by the maximum possible absolute difference between Ethan's algorithm's output and the correct answer. |
|
Then, output a line containing as single integer <strong>E</strong>, the number of edges in your chosen graph which yields the above maximum absolute difference. |
|
Then, output <strong>E</strong> lines, the <em>j</em>th of which contains three integers |
|
<strong>U<sub>j</sub></strong>, <strong>V<sub>j</sub></strong>, and <strong>W<sub>j</sub></strong> denoting that |
|
there is an edge between nodes <strong>U<sub>j</sub></strong> and <strong>V<sub>j</sub></strong> with weight <strong>W<sub>j</sub></strong>. |
|
</p> |
|
|
|
<p> |
|
Note that there must be no self-loops (no edge may connect a node to itself), and no two edges may connect the same unordered pair of nodes. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
|
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 200 <br /> |
|
2 ≤ <strong>N</strong> ≤ 50 <br /> |
|
1 ≤ <strong>K</strong> ≤ 50 <br /> |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
|
|
<p> |
|
In the first case, there are exactly two possible valid graphs, either of which would be accepted: |
|
</p> |
|
|
|
<pre> |
|
1 |
|
1 2 1 |
|
|
|
1 |
|
2 1 1 |
|
</pre> |
|
|
|
<p> |
|
In each of the above graphs, Ethan's algorithm's answer and the correct answer are both equal to 1. |
|
There's an absolute difference of 0 between those answers, which is the maximum possible absolute difference. |
|
</p> |
|
|
|
<p> |
|
In the second case, one possible graph which would be accepted is as follows (with Ethan's algorithm's answer and the correct answer both equal to 42): |
|
</p> |
|
|
|
<pre> |
|
1 |
|
1 2 42 |
|
</pre> |
|
|
|
<p> |
|
In the third case, one possible graph which would be accepted is as follows (with Ethan's algorithm's answer and the correct answer both equal to 1): |
|
</p> |
|
|
|
<pre> |
|
3 |
|
1 2 2 |
|
4 1 1 |
|
4 2 1 |
|
</pre> |
|
|
|
<p> |
|
Putting those together, the following is one possible sequence of outputs for the first 3 cases which would be accepted: |
|
</p> |
|
|
|
<pre> |
|
Case #1: 0 |
|
1 |
|
1 2 1 |
|
Case #2: 0 |
|
1 |
|
1 2 42 |
|
Case #3: 0 |
|
3 |
|
1 2 2 |
|
4 1 1 |
|
4 2 1 |
|
</pre> |
|
|
|
<p> |
|
Do not output the line "<strong>Multiple possible accepted graphs</strong>". |
|
</p> |
|
|
|
|