408312: GYM103091 L Ambiguous

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Ambiguoustime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Stan Ford is a city planner who has been hired by MTL, Stanford's president, to solve a very important problem. Stan has been tasked with finding a new location for Stanford's campus. As lovely as Palo Alto is, Stanford has grown tired of being so close to Berkeley and wants to move to the great state of Kansas.

Within Kansas, there are $$$N$$$ cities, and $$$M$$$ one directional roads that connect cities. In Kansas, it is guaranteed that if you leave from a city, it is impossible to return to that city by traveling along the roads.

Stan Ford needs to find a city that is ambiguous to report back to MTL. A city, $$$u$$$, is ambiguous if for every other city $$$v$$$, Stan can either walk from $$$u$$$ to $$$v$$$, or from $$$v$$$ to $$$u$$$. During these walks, he can of course pass through other cities that aren't $$$u$$$ or $$$v$$$.

However, MTL is quite meticulous, and wants to make sure that he is able to consider all possible home cities for Stanford. Thus, he wants to know from Stan Ford, the number of ambiguous cities that exist in Kansas. Poor Stan is tired of walking, and asks for your help in counting the number of ambiguous cities!

Input

The first line will contain two space separated integers $$$N$$$ and $$$M$$$ ($$$ 2 \leq N \leq 200,000$$$, $$$1 \leq M \leq 200,000$$$) which represents the number of cities and roads respectively. The next $$$M$$$ lines will contain two space separated integers $$$u$$$ and $$$v$$$ ($$$ 1 \leq u, v \leq N$$$) which means there is a road from city $$$u$$$ to city $$$v$$$.

Output

Output a single integer, the number of ambiguous cities in the graph.

ExampleInput
4 4
1 2
1 3
2 4
3 4
Output
2

加入题单

算法标签: