LCA
Medium
Execution time limit is 2 seconds
Runtime memory usage limit is 128 megabytes
The directed graph is given. How many pairs of vertices have the common ancestor? The common ancestor of vertices and is a vertex for which and are reachable from .
Input
The first line contains the number of vertices and number of edges in a graph. Each of the next lines contains two numbers from to . The pair means that an edge goes from to .
Output
Print the number of pairs.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 1K
Acceptance rate 27%