Graph condensation
You are given a directed graph with $N$ vertices and $M$ edges ($1\le N\le 20,000$, $1\le M\le 200,000$). Find the components of the strong connectivity of a given graph and topologically sort its condensation.
The graph is specified in the input file as follows: the first line contains the numbers $N$ and $M$. Each of the following $M$ lines contains a description of the edge — two integers from the range from $1$ to $N$ — the numbers of the beginning and end of the edge.
On the first line, print the number $K$ — the number of components of strong connectivity in a given graph. On the next line, print $N$ numbers — for each vertex, print the number of the component of strong connectivity to which this vertex belongs. The components of strong connectivity must be numbered in such a way that for any edge the number of the component of strong connectivity of its beginning does not exceed the number of the component of strong connectivity of its end.
10 19 1 4 7 8 5 10 8 9 9 6 2 6 6 2 3 8 9 2 7 2 9 7 4 5 3 6 7 3 6 7 10 8 10 1 2 9 2 7
2 1 2 2 1 1 2 2 2 2 1