Nice Report
Time limit5sMemory limit512 MB
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 is subscribed to user , user is not necessarily subscribed to user .
Andrew's boss asked him to find, for each user , the number of users such that user can be reached from user 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 and (): the number of users and the number of subscriptions. Each of the next lines contains integers and (, ), meaning user is subscribed to user . Each ordered pair appears at most once in the input.
Output
For each user , print an approximate number of users reachable from user . Let be the correct count. The answer is accepted if and 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.