0084. Matrix Multiplication

Input file name: matrix.in
Output file name: matrix.out
Time limit: 250 ms
Memory limit: 16 megabytes

Let us consider undirected graph G = <V,E > which has N vertices and M edges. Incidence matrix of this graph is N *M matrix A = {aij}, such that aij is 1 if i-th vertex is one of the ends of j-th edge and 0 in the other case. Your task is to find the sum of all elements of the matrix ATA.

Input file

The first line of the input file contains two integer numbers – N and M (2 ≤ N ≤ 10,000, 1 ≤ M ≤ 100,000). 2M integer numbers follow, forming M pairs, each pair describes one edge of the graph. All edges are different and there are no loops (i.e.  edge ends are distinct).

Output file

Output the only number – the sum requested.

Examples:

matrix.inmatrix.out
4 4 1 2 1 3 2 3 2 4 18


Source: Petrozavodsk Winter 2003. St. Petersburg Contest II, Thursday, February 06

Discuss       Submit a solution



Printable version