Counting on a directed graph

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Given an directed graph with N nodes (numbered from 1 to N) and M edges, calculate the number of unordered pairs (X, Y) such there exist two paths, one from node 1 to node X, and another one from node 1 to node Y, such that they don't share any node except node 1.
Input
There is only one test case in one test file.
The first line of each test case contains two space separated integers N, M. Each of the next M lines contains two space separated integers u, v denoting a directed edge of graph G, from node u to node v. There are no multiedges and self loops in the graph.
Output
Print a single integer corresponding to the number of unordered pairs as asked in the problem..
Constraints and Subtasks
 1 ≤ N ≤ 10^{5}
 0 ≤ M ≤ 5 * 10^{5}
Subtask 1: (30 points)
 The graph is a Directed Acyclic Graph (DAG) i.e. there is no cycle in the graph.
Subtask 2: (20 points)
 N * M ≤ 50000000
Subtask 3 (50 points)
 No additional constraints
Example
Input: 6 6 1 2 1 3 1 4 2 5 2 6 3 6 Output: 14
Explanation
There are 14 pairs of vertices as follows:
(1,2)
(1,3)
(1,4)
(1,5)
(1,6)
(2,3)
(2,4)
(2,6)
(3,4)
(3,5)
(3,6)
(4,5)
(4,6)
(5,6)
Author:  ztxz16 
Tester:  kevinsogo 
Editorial  http://discuss.codechef.com/problems/GRAPHCNT 
Tags  dominator, may15, mediumhard, ztxz16 
Date Added:  25032015 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 