Under construction

Still being built. Things may change

Nice Report

Time limit5sMemory limit512 MB

Summary
For each vertex of a directed graph, estimate how many vertices it can reach, with each estimate within a factor of two of the exact count.
Level

Hard8 of 10

Topics
Graph, Probability, Topological sort
Solved
No attempts yet

Problem

Andrew is analyzing the subscription graph of a social network. The graph is directed: if user aa is subscribed to user bb, user bb is not necessarily subscribed to user aa.

Andrew's boss asked him to find, for each user xx, the number of users yy such that user yy can be reached from user xx in the subscription graph.

The exact values are not needed. They look ugly and become irrelevant almost immediately, so Andrew wants approximate values. Find values that differ from the correct ones by at most a factor of two.

Input

The first line contains two integers nn and mm (1≤n,m≤2000001 \le n, m \le 200000): the number of users and the number of subscriptions. Each of the next mm lines contains integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i), meaning user aia_i is subscribed to user bib_i. Each ordered pair (ai,bi)(a_i, b_i) appears at most once in the input.

Output

For each user ii, print an approximate number qiq_i of users reachable from user ii. Let ziz_i be the correct count. The answer is accepted if qi≤2ziq_i \le 2z_i and zi≤2qiz_i \le 2q_i hold for every user. You may output any value for up to 10 users.

The judges check answers against exact values, but they do not promise that exact values can be computed within the time and memory limits of this problem. Approximate values are recommended.

In the example, user 1 can reach all five users. The answer 7 is acceptable because it differs from 5 by less than a factor of two. Similarly, the answer 2 is acceptable for user 4.

Examples1

  1. Example 1

    Input
    5 6
    1 2
    1 3
    2 4
    2 5
    3 5
    4 2
    
    Expected output
    7
    3
    2
    2
    1