acdeream Matrix Multiplication

时间:2022-02-13 10:50:30

D - Matrix Multiplication

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

      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 = {ai,j}, such that ai,j 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

      The first line of the input file contains two integer numbers — N and M (2 ≤ N ≤ 10 000, 1 ≤ M ≤100 000). Then 2*M 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

      Output the only number — the sum requested.

Sample Input

4 4
1 2
1 3
2 3
2 4

Sample Output

18
 /*
* this code is made by 987690183
* Problem: 1213
* Verdict: Accepted
* Submission Date: 2014-10-14 13:40:27
* Time: 236MS
* Memory: 1716KB
*/
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; int num[];
long long get(int n,int m)/**Cn,m**/
{
long long sum = ;
for(int i=,j=n;i<=m;i++,j--)
sum=sum*j/i;
return sum;
}
int main()
{
int n,m,x,y;
int hxl= ;
while(scanf("%d%d",&n,&m)>)
{
memset(num,,sizeof(num));
for(int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
num[x]++;
num[y]++;
hxl = hxl+;
}
long long tom = hxl;
for(int i=;i<=;i++)
if(num[i]>=)
{
tom=tom+get(num[i],)*;
}
printf("%lld\n",tom);
}
return ;
}