File size: 4,258 Bytes
ab396f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
<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>
|