Making test data 1

Time limit1sMemory limit128 MB

Summary
Construct one shortest-path test input that makes Floyd-Warshall exceed 10^6 operations while keeping Dijkstra under it, using as few integers as possible.
Level

Medium7 of 10

Topics
Graph, Shortest path, Greedy, Implementation
Solved
No attempts yet

Problem

Writing a good contest problem is hard. The hardest part is often the test data. Good tests must separate a solution that follows the intended approach from one that does not. They must also catch a program that is right on most inputs and fails only on a special case.

This task does not ask you to compute shortest paths. It asks you to print test data.

Build one input XX for a weighted directed shortest-path problem. XX must satisfy both of the following for the two programs below.

  1. Modified Dijkstra must not time out on XX.
  2. Floyd-Warshall must time out on XX.

Smaller data is better. XX may contain at most 10710^7 integers.

Both programs keep a counter\mathrm{counter} of operations. If counter\mathrm{counter} exceeds 10610^6, the program times out.

XX uses this format.

The first line is the number of vertices VV. Vertices are numbered from 00 to V−1V-1.

Each of the next VV lines describes the outgoing edges of one vertex, starting from vertex 00. The first number on the line is the out-degree nin_i, followed by nin_i pairs (j,w)(j, w). Each pair is an edge from that vertex to jj with weight ww.

The next line is the number of queries QQ. Each of the next QQ lines has a start ss and a target tt.

The data must obey these limits.

  • 1≤V≤3001 \le V \le 300
  • nin_i is a non-negative integer
  • 0≤j<V0 \le j < V
  • ∣w∣<106|w| < 10^6
  • 0≤∑ni≤50000 \le \sum n_i \le 5000
  • 1≤Q≤101 \le Q \le 10
  • 0≤s,t<V0 \le s, t < V
  • no query start can reach a negative cycle

If a pair is unreachable, its shortest-path value is 10910^9.

If several inputs satisfy the conditions, keep the one with the fewest integers. If there is still a tie, compare the integers in the order they appear as a sequence and keep the lexicographically smallest sequence.

Input

There is no input.

Output

Print the unique input chosen by the rules above.

The first line is VV.

Each of the next VV lines is the out-degree and the edge list of one vertex. If a vertex has no outgoing edges, print 00 on that line.

The next line is QQ.

Each of the next QQ lines is ss and tt separated by a space.

Hint

Floyd-Warshall runs on an adjacency matrix MM as follows.

counter = 0
for k = 0 to V-1:
    for i = 0 to V-1:
        for j = 0 to V-1:
            counter = counter + 1
            if counter > 1000000: TLE
            M[i][j] = min(M[i][j], M[i][k] + M[k][j])

The iteration count is always V3V^3. It does not depend on the number of edges or queries.

Modified Dijkstra runs the following for each query (s,t)(s, t). Initially dist[s]=0\mathrm{dist}[s] = 0 and every other distance is infinite.

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

counter\mathrm{counter} is the number of priority-queue pops. If a vertex is relaxed more than once, it can enter the queue more than once.

Examples1

  1. Example 1

    Input
    Expected output
    101
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    1
    0 0