Under construction

Still being built. Things may change

Graph that exceeds Dijkstra's counter

Time limit1sMemory limit128 MB

Summary
Print the exact constructed directed weighted graph that makes Floyd-Warshall finish while the lazy-deletion Dijkstra times out on one query.
Level

Easy3 of 10

Topics
Graph, Shortest path, Implementation
Solved
No attempts yet

Problem

Writing contest test data is hard. Good data must separate a solution that matches the problem from one that does not. It must also catch a program that is right on most inputs and wrong on a special case.

This problem asks you to print a directed weighted graph that separates two shortest-path programs. Graph XX must satisfy both of the following.

  1. Program A (Floyd-Warshall) must not time out on XX.
  2. Program B (modified Dijkstra) must time out on XX.

Each program keeps a counter of operations. If the counter exceeds 10610^6, the run is a time out. Smaller data is better, so the printed graph may contain at most 157157 integers.

Floyd-Warshall raises its counter by exactly V3V^3 for a graph with VV vertices. If V≤100V \le 100, program A does not time out.

Modified Dijkstra may push the same vertex onto a priority queue more than once. Negative edges can make the number of pops grow exponentially. Chaining kk triangle gadgets below makes the modified Dijkstra counter grow exponentially, while the Floyd-Warshall counter stays (2k+1)3(2k+1)^3.

Many graphs meet the time-out conditions. The judge accepts only the unique graph defined by the rules below.

Set V=2k+1V = 2k+1 and number vertices from 00 to 2k2k. Every edge is directed.

  • Vertex 00 has no outgoing edges.
  • Vertex 11 has one edge to vertex 00 with weight 11.
  • Vertex 22 has one edge to vertex 11 with weight 11.
  • For each integer t=1,2,…,k−1t = 1, 2, \ldots, k-1 do the following.
    • Vertex 2t+12t+1 has one edge to vertex 2t2t with weight −2⋅2t-2 \cdot 2^{t}.
    • Vertex 2t+22t+2 has two edges. The first goes to vertex 2t+12t+1 with weight 2t2^{t}. The second goes to vertex 2t2t with weight 00.

There is one query. The source is 2k2k and the target is 00.

Input

The first line contains the number of triangle gadgets kk. (1≤k≤161 \le k \le 16)

For this kk, V=2k+1≤33V = 2k+1 \le 33, so the Floyd-Warshall counter does not exceed 10610^6. The number of printed integers is 8k+38k+3, which is at most 157157. Every weight ww satisfies ∣w∣<106|w| < 10^6.

Output

Print the graph defined above in the following format.

Print VV on the first line.

The next VV lines describe outgoing edges. Line ii (with ii starting at 00) starts with nin_i, the number of outgoing edges of vertex ii, then nin_i pairs jj ww separated by spaces. jj is the head and ww is the weight. If a vertex has more than one edge, print them in the order given in the statement.

Print 11 on the next line, the number of queries.

Print 2k2k and 00 on the last line, separated by a space.

Hint

The counters in programs A and B follow the pseudocode below.

Floyd-Warshall:

counter = 0
for x = 0 to V-1
    for i = 0 to V-1
        for j = 0 to V-1
            counter = counter + 1
            M[i][j] = min(M[i][j], M[i][x] + M[x][j])

Modified Dijkstra (once per query):

dist[s] = 0
pq.push((0, s))
while pq is not empty
    counter = counter + 1
    (d, u) = pq.pop()
    if d == dist[u]
        for each edge (u, v, w) from u
            if dist[u] + w < dist[v]
                dist[v] = dist[u] + w
                pq.push((dist[v], v))

The priority queue pops the pair with the smaller distance first.

Examples3

  1. Example 1

    Input
    1
    
    Expected output
    3
    0
    1 0 1
    1 1 1
    1
    2 0
    
  2. Example 2

    Input
    2
    
    Expected output
    5
    0
    1 0 1
    1 1 1
    1 2 -4
    2 3 2 2 0
    1
    4 0
    
  3. Example 3

    Input
    3
    
    Expected output
    7
    0
    1 0 1
    1 1 1
    1 2 -4
    2 3 2 2 0
    1 4 -8
    2 5 4 4 0
    1
    6 0