WEBISL - Web islands

no tags 

For a given set of web pages, we want to find largest subsets such that from every page in a subset you can follow links to any other page in the same subset.

Input

On the first line, there are two numbers, number of the pages N, and total number of links M. Pages are numbered from 0 up to N-1. On lines 2 up to M+1, there are two numbers per line. The first is the source page and the second is the target page of a link.

Output

On N lines there is a component ID for every single page. The componet ID is the smallest page index on the component.

Example

Input:
3 3
0 1
1 0
1 2

Output: 0
0
2

hide comments
Kishlay Raj: 2014-04-19 16:01:54

any1 plz xplain


Added by:dRak
Date:2013-03-04
Time limit:1s-5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64