#P10265. Maze Connectivity Sum
Maze Connectivity Sum
Maze Connectivity Sum
In a mysterious fantasy continent, there exist ancient and magical mazes numbered from to . Some pairs of mazes have bidirectional connections, while others have one-way paths. A player wants to challenge different mazes by starting from maze . Your task is to help him determine the total count by calculating (1) the number of mazes that can directly reach maze , and (2) the number of mazes that maze can directly reach; then output the sum of these two counts.
Note that for any maze (), it is always considered to directly reach itself.
inputFormat
The input begins with a line containing two integers and , where is the total number of mazes and is the starting maze. The second line contains an integer , representing the number of direct connections (excluding the implicit self-connection). Each of the following lines contains two integers and , indicating there is a direct connection from maze to maze .
outputFormat
Output a single integer: the sum of the number of mazes that can directly reach maze and the number of mazes that maze can directly reach (each maze always directly reaches itself).
sample
4 2
4
1 2
2 3
3 2
2 4
6