Graph that exceeds Dijkstra's counter
Time limit1sMemory limit128 MB
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 must satisfy both of the following.
- Program A (Floyd-Warshall) must not time out on .
- Program B (modified Dijkstra) must time out on .
Each program keeps a counter of operations. If the counter exceeds , the run is a time out. Smaller data is better, so the printed graph may contain at most integers.
Floyd-Warshall raises its counter by exactly for a graph with vertices. If , 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 triangle gadgets below makes the modified Dijkstra counter grow exponentially, while the Floyd-Warshall counter stays .
Many graphs meet the time-out conditions. The judge accepts only the unique graph defined by the rules below.
Set and number vertices from to . Every edge is directed.
- Vertex has no outgoing edges.
- Vertex has one edge to vertex with weight .
- Vertex has one edge to vertex with weight .
- For each integer do the following.
- Vertex has one edge to vertex with weight .
- Vertex has two edges. The first goes to vertex with weight . The second goes to vertex with weight .
There is one query. The source is and the target is .
Input
The first line contains the number of triangle gadgets . ()
For this , , so the Floyd-Warshall counter does not exceed . The number of printed integers is , which is at most . Every weight satisfies .
Output
Print the graph defined above in the following format.
Print on the first line.
The next lines describe outgoing edges. Line (with starting at ) starts with , the number of outgoing edges of vertex , then pairs separated by spaces. is the head and is the weight. If a vertex has more than one edge, print them in the order given in the statement.
Print on the next line, the number of queries.
Print and 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.