K-edges graph
Very easy
Execution time limit is 2 seconds
Runtime memory usage limit is 512 megabytes
You are given an acyclic directed graph, consisting of n nodes and k edges. Find the number of edges in its transitive closure.
Transitive closure of graph G is a graph G', consisting of all nodes of original graph G and such edges (u, v) that there is a path from node u to v in graph G.
Knuth knows how to solve the problem. And what about you?
Input
The first line contains two numbers n and k (1 ≤ n, k ≤ 50000). Then k lines follow, each containing two integers a[i]
and b[i]
, describing directed edge from a[i]
to b[i]
(1 ≤ a[i]
, b[i]
≤ n). Graph doesn't contain loops, cycles and multiple edges.
Output
Print the number of edges in transitive closure.
Examples
Input #1
Answer #1
Submissions 376
Acceptance rate 30%