Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this graph is N * M matrix A = {a ij}, such that a ij 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 A TA.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Input

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

Output the only number - the sum requested.

Sample Input

1

4 4

1 2

1 3

2 3

2 4

Sample Output

18

要注意多组输入之下加n组输入,而且zoj不支持%I64d所以只能用%lld

题意就是给你n,m代表n个顶点m条边,然后m行每行俩数代表x到y有一条边

所以在矩阵里面如果有哪两个点之间有一条边则为1否则为0,然后求矩阵与其转置矩阵的乘积,

而且是无向边,看似很复杂的一道题但是如果把矩阵及其转置矩阵给列出来的话会发现,这是一种矩阵的特殊情况,即矩阵和它的转置矩阵是对称的,那么再求积的话,相当于求某个顶点的平方和,

对于每组顶点的输入用数组记录每个顶点出现的次数,然后把每个顶点的平方和加起来就行了

#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; typedef long long ll;
const int maxn=10005;
const int INF=0x3f3f3f3f; ll t,n,m,x,y;
ll a[maxn]; int main()
{
while(~scanf("%lld",&t))
{
while(t--)
{
ll i;
memset(a,0,sizeof(a));
scanf("%lld %lld",&n,&m);
while(m--)
{
scanf("%lld %lld",&x,&y);
a[x]++;
a[y]++;
}
ll sum=0;
for(i=1; i<=n; i++) sum+=a[i]*a[i];
printf("%lld\n",sum);
if(t)
printf("\n");
}
}
return 0;
}

D - Matrix Multiplication ZOJ - 2316 规律题的更多相关文章

  1. ZOJ 2316 Matrix Multiplication

    Matrix Multiplication Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on ZJU. O ...

  2. 矩阵乘法 --- hdu 4920 : Matrix multiplication

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  3. hdu4920 Matrix multiplication 模3矩阵乘法

    hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  4. hdu 4920 Matrix multiplication(矩阵乘法)2014多培训学校5现场

    Matrix multiplication                                                                           Time ...

  5. PKU 3318 Matrix Multiplication(随机化算法||状态压缩)

    题目大意:原题链接 给定三个n*n的矩阵A,B,C,验证A*B=C是否成立. 所有解法中因为只测试一组数据,因此没有使用memset清零 Hint中给的傻乎乎的TLE版本: #include<c ...

  6. 【数学】Matrix Multiplication

                                 Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  7. hdu 4920 Matrix multiplication bitset优化常数

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  8. acdeream Matrix Multiplication

    D - Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

  9. HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

随机推荐

  1. Jmeter-7-在命令行中运行Jmeter.

    jmeter -n -t D:\Jmeter_result\Script_baidu.jmx -l D:\Jmeter_result\Script_baidu.txt jmeter -n -t D:\ ...

  2. JSX语法规范

    1.只有一个开始节点和一个尾节点 正确的写法 ReactDOM.render( <div>hello,你好</div>, document.body ) 错误的写法,开始节点和 ...

  3. FJOI游记(日记向 不定期更新)

    emmmm说实话只是突发奇想开个blog记录记录自己的内心想法罢了.. 2017/12/22:刷了一周的计算几何..刷的死去活来..结果还是被D惨了...譬如都不会考,要考我都不会什么的...感觉内心 ...

  4. OOM有哪些情况,SOF有哪些情况

    OOM 1.全称为OutOfMemoryError异常,如果虚拟机在扩展栈时无法申请足够的内存空间,抛出它: 2.Java heap异常:java.lang.OutOfMemoryError:Java ...

  5. make command explaination 編譯命令解釋

    Creating .config file make ARCH=arm CROSS_COMPILE=arm-none-eabi- stm32_defconfig 以上命令是 將變數 ARCH=arm, ...

  6. python基础===函数的几个要点

    函数 可接受任意数量参数的函数 位置参数   和  关键字参数 为了能让一个函数接受任意数量的位置参数,可以使用一个*参数. def avg(first, *r): return (first + s ...

  7. wifi驱动移植

    目标板:Hi3518 内核版本:linux3.0.8   1.修改makefile #PLATFORM = PC //注释掉 PLATFORM = HI3518 //支持平台 ifeq ($(PLAT ...

  8. maven使用备忘

    maven的所有功能本质上都是通过插件来实现的所有的功能.archetype插件就是根据项目类型创建项目的插件.执行archetype:generate命令就会list一系列的项目类型,可以选择一个合 ...

  9. Nginx-进程模型

    1.整体框架 正常执行起来的Nginx有很多进程,有master_process和worker_process进程,master_process是监控进程即主线程,worker_process是工作进 ...

  10. 光流optical flow基本原理与实现

    光流(optical flow)是什么呢?名字很专业,感觉很陌生,但本质上,我们是最熟悉不过的了.因为这种视觉现象我们每天都在经历.从本质上说,光流就是你在这个运动着的世界里感觉到的明显的视觉运动(呵 ...