Longest paths

Write a program such that, given a directed graph without cycles, computes the number of vertices of the longest path in the graph, and the number of paths with this length.

Input

Input consists of several cases. Every case begins with the number of vertices nn and the number of edges mm. Follow mm pairs xyx \enspace y indicating that there is an arc from xx to yy. There are no repeated arcs. Vertices are numbered starting at 0. Assume 1n1041 \le n \le 10^4 and 0m5n0 \le m \le 5n.

Output

For every case, print two numbers: the length of the longest path, and how many paths have this length. The test cases are such that both values fit into an integer number.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:16:22.844Z

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