Balance Scale
InterviewTime limit1sMemory limit256 MB
Given pairwise heavier-than results, count for each object how many others have no implied comparison.
Problem
There are objects, all of different weights, numbered 1 to . For some pairs of objects you already measured on a balance scale which one is heavier, and those results are collected in a table. From that table you can sometimes work out the comparison for a pair you never measured, and sometimes you cannot.
Suppose there are 6 objects and the five measured results are , , , , , where means the weight of object . From and you get . For objects 2 and 6, the table says nothing about which one is heavier. So object 2 has a known comparison against objects 1, 3, and 4, and an unknown comparison against objects 5 and 6. Object 4 has a known comparison against every other object.
The input never contradicts itself. Suppose were added to the example above. From and you derive , which conflicts with the measured . Such an input is never given.
Given the number of objects and the measured results for some pairs, write a program that prints, for each object, how many objects its comparison result is unknown against.
Input
The first line contains the number of objects . The second line contains the number of measured pairs . Here and . Each of the next lines holds one measured result: two integers separated by a space, where the first object is heavier than the second.
Output
Print the answers on lines. Line holds the number of objects whose comparison against object is unknown.