Transitive closure

Write a program to compute the transitive closure of a directed graph with nn vertices. That is, you must compute an n×nn \times n matrix where at the jj-th column of the ii-th row there is a 1 if it is possible to go from ii to jj, and there is a 0 otherwise.

Input

Input consists of several cases. Every case begins with nn followed by the number of arcs mm. Follow mm pairs xx yy to indicate an arc from xx to yy, with xyx \ne y. Assume 1n2001 \le n \le 200, that the vertices are numbered between 0 and n1n - 1, and that there are no repeated arcs.

Output

For every graph, print its transitive closure, followed by a line with 20 dashes.

Observation

In the “large” private test cases, we have m=Θ(n2)m = \Theta(n^2).

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:23:45.083Z

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