Number of shortest paths

Given a directed graph, compute in how many ways every vertex is
reachable from the vertex 0 making the minim number of steps.

Input

Input consists of several cases, each one with the number of vertices n
(between 1 and 10⁴), the number of arcs m (between 0 and 10n), and m
pairs x y to indicate an arc from x to y. There are no repeated arcs,
nor of the kind x x. Vertices are numbered from 0 to n − 1.

Output

For every case, and for every vertex x, print its number, the minimum
number of steps to reach x starting from 0, and in how many different
ways this can be done. Print a -1 if a vertex is unreachable from 0.
Print an empty line after every case.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:56:14.974Z

© Jutge.org, 2006–2026.
https://jutge.org
