Misimplemented Dinic
Time limit2sMemory limit512 MB
Print a fixed 4-vertex, 5-edge flow network; there is no input and the output is a single constant graph.
- Level
Easy3 of 10
- Topics
- Graph, Brute force, Implementation
- Solved
- No attempts yet
Problem
Jigui always solves flow problems with the Edmond-Karp algorithm. One day Jigui saw a flow problem with 500 vertices and 100000 edges. Jigui built a flow graph, wrote about 2000 bytes of code, and submitted it, but the submission was not accepted. Tired of tuning the code, Jigui found Dinic's algorithm, whose worst-case time complexity is .
Dinic's algorithm is as follows.
- Treat every residual edge as an edge of length 1 and compute the shortest-path distance from the source to every vertex.
- Find an augmenting path with DFS and push flow. Push flow on an edge only when .
- Repeat steps 1 and 2 until no more flow can be pushed.
The bound is justified as follows.
- Steps 1 and 2 run at most times. Each run increases by at least 1, and cannot exceed .
- Step 1 is . It can be computed with BFS.
- Step 2 is . Each time flow is pushed, at least one edge becomes saturated, so there are at most augmenting paths. Each augmenting path has length at most .
Jigui implemented the algorithm carefully and still did not get an accepted verdict. Dotori looked at the code and pointed out a small mistake: when the search for an augmenting path starts, edges that cannot carry more flow are scanned from the beginning of the adjacency list every time. Jigui will not believe this until a small example graph is shown.
Help Dotori print that example graph. The graph to print is unique.
The problem Jigui is solving sends flow from vertex 1 to vertex . Edges are stored in a linked list, and a new edge is inserted at the front of the list, so a later input edge is used first.
Input
There is no input.
Output
Print the number of vertices and the number of edges on the first line. is and is .
Then print lines, each with a start vertex , an end vertex , and a capacity , in this order:
- from to with capacity
- from to with capacity
- from to with capacity
- from to with capacity
- from to with capacity
The graph has no duplicate edges. Each line prints the integers , , and in that order, separated by spaces.