Ethan is doing his third programming assignment: finding the shortest path between two nodes in a graph.
Given an undirected, weighted graph with N nodes (numbered from 1 to N), having no self-loops or duplicate edges, Ethan must compute the length of the shortest path from node 1 to node N. Ethan has implemented an algorithm to solve this problem, described by the following pseudocode:
- Set i to be equal to 1, and d to be equal to 0
- If i is equal to N, output d and stop
- Find the edge incident to node i that has the smallest weight (if no edges are incident to i or if there are multiple such edges tied with the smallest weight, then crash instead)
- Increase d by the weight of this edge, and set i to be equal to the other node incident to this edge
- Return to Step 2
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.
You're given the number of nodes in the graph N, as well as the maximum allowable edge weight K (each edge's weight must be an integer in the interval [1, K]). Under these constraints you want to maximize the absolute difference between Ethan's output and the actual shortest distance between nodes 1 and N. However, you don't want Ethan's algorithm to either crash or run forever. Note that node N 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.
Input
Input begins with an integer T, the number of graphs. For each graph, there is a line containing the space-separated integers N and K.
Output
For the _i_th graph, first output a line containing "Case #i: " 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 E, the number of edges in your chosen graph which yields the above maximum absolute difference. Then, output E lines, the _j_th of which contains three integers Uj, Vj, and Wj denoting that there is an edge between nodes Uj and Vj with weight Wj.
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.
Constraints
1 ≤ T ≤ 200
2 ≤ N ≤ 50
1 ≤ K ≤ 50
Explanation of Sample
In the first case, there are exactly two possible valid graphs, either of which would be accepted:
1
1 2 1
1
2 1 1
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.
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):
1
1 2 42
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):
3
1 2 2
4 1 1
4 2 1
Putting those together, the following is one possible sequence of outputs for the first 3 cases which would be accepted:
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
Do not output the line "Multiple possible accepted graphs".