Jigui implemented the Bellman-Ford algorithm to decide whether a directed graph whose edge weights are all 1 or −1 has a negative cycle.
- Set d[v]=0 for every vertex v.
- One round scans every edge (s,e,w) in the order given in the input and assigns min(d[e], d[s]+w) to d[e]. Each edge changes d right away, so the next edge of the same round reads the changed values.
- Repeat the round N−2 times. It should have been N−1 times.
- Run one more round. If any value of d changes during that round, report that a negative cycle exists.
Because step 3 runs one round too few, the code reports a negative cycle on a graph that has none. Build such a graph yourself and show that Jigui's code is wrong.
You are given the number of vertices N. Print a directed graph on N vertices whose edge weights are all 1 or −1, that has no negative cycle, and that the code above declares to have one. The order in which you print the edges is the order in which the code scans them, so the order is part of the answer.
Many graphs satisfy the conditions. Print the one with the smallest number of edges M. If several graphs remain, lay the printed edges out as the sequence s1,e1,d1,s2,e2,d2,…,sM,eM,dM, compare the sequences number by number, and print the one that comes first.