Ringteed
Time limit1sMemory limit1024 MB
Count the squares where a simple walk starting at square S can end in a connected graph whose cycles share no vertices.
Problem
Bit, a boy who likes to walk around his home city, lives in Bytetown, the capital of Byteland.
The road network of Bytetown consists of squares connected by streets. From any square, one can reach every other square along the streets.
If, starting from some square, one can move along streets and return to that same square without visiting any square or street twice on the way, the route is called a ring road. A notable property of Bytetown's network is that no square lies on more than one ring road.
Bit has just come up with a new plan for how he will walk from now on. Each day he steps out of his house onto the square in front of it. He picks a street starting there and follows it to the next square, where he picks another street to continue. During one walk he never visits the same square twice. He keeps walking until he reaches a square from which every street leads to a square he has already visited. Then he declares the walk finished and takes the bus home.
Write a program that finds the number of different squares where Bit's walks can end.
Input
The first line contains the space-separated integers , , and : the number of squares, the number of streets, and the number of the square in front of Bit's house. The constraints are , , and .
Each of the next lines contains two integers and (, , ), meaning there is a street between squares and . Any two squares are connected by at most one street.
Output
Print a single integer: the number of squares where Bit's walks can end.