Matrix Multiplication

Time Limit: 2000ms
Memory Limit: 32768KB

This problem will be judged on ZJU. Original ID: 2316
64-bit integer IO format: %lld      Java class name: Main

 

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.

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

 

Source

 
解题:题意转化后,就是计算途中有多少条,长度为2的路径。注意是无向图。。。。每个顶点,看它的度是多少。从这些度里面选取2个的组合数。。。。。。
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int d[maxn];
int main() {
int t,u,v,n,m,ans;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
memset(d,,sizeof(d));
for(int i = ; i < m; i++){
scanf("%d %d",&u,&v);
++d[u];
++d[v];
}
ans = ;
for(int i = ; i <= n; i++)
ans += d[i]*(d[i]-)/;
ans = (ans + m)<<;
printf("%d\n",ans);
if(t) puts("");
}
return ;
}

ZOJ 2316 Matrix Multiplication的更多相关文章

  1. zoj 2316 Matrix Multiplication 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2316 题目意思:有 N 个 点,M 条 边.需要构造一个N * ...

  2. 【数学】Matrix Multiplication

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

  3. hdu 4920 Matrix multiplication bitset优化常数

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

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

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

  5. hdu4920 Matrix multiplication 模3矩阵乘法

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

  6. acdeream Matrix Multiplication

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

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

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

  8. Matrix multiplication hdu4920

    Problem Description Given two matrices A and B of size n×n, find the product of them. bobo hates big ...

  9. HDU-4920 Matrix multiplication

    矩阵相乘,采用一行的去访问,比采用一列访问时间更短,根据数组是一行去储存的.神奇小代码. Matrix multiplication Time Limit: 4000/2000 MS (Java/Ot ...

随机推荐

  1. C语言播放声音最简单的两种方法

    1. 假设仅须要播放波形文件wav格式的声音,非常easy.仅仅需一句话: PlaySound(TEXT("Data\\1.wav"), NULL, SND_FILENAME | ...

  2. DNS负载均衡 Nginx 负载均衡的种类

    DNS负载均衡 当一个网站有足够多的用户的时候,假如每次请求的资源都位于同一台机器上面,那么这台机器随时可能会蹦掉.处理办法就是用DNS负载均衡技术,它的原理是在DNS服务器中为同一个主机名配置多个I ...

  3. find命令用法举例

    显示7天前(后)的时间 for linux “find”的用法: 删除”/tmp”目录下,7天前的文件 find /tmp -name "*" -type f-mtime +7 - ...

  4. ThinkPHP搜索框需要注意的事项

    1.当搜索成功后需要用到分页的时候,form表单需要用get传参 2.编码方式 当编码方式不正确的时候,使用分页类改变分页,会使搜索框里面的内容乱码 改变编码方式的方法 第一种:header(&quo ...

  5. Codeforces Round #454

    Masha and Bears Tic-Tac-Toe Shockers Seating of Students Party Power Tower Reverses

  6. (转) 50个CSS技巧

    这里我工作中收集了10个很不错的CSS技巧,你可以用在你的项目上.它可以帮你很好地整理你的元素并让他们看起来蛮酷的.下面开始我们的内容,希望你会喜欢它.下面是我收集的CSS技巧,希望能帮助到你,感觉收 ...

  7. javascript时间戳转换成yyyy-MM-DD格式

    最近开发中需要和后端进日期和时间传值,前后端约定为时间戳的格式,但是前端展示需要展示成年-月-日的格式.就需要进行日期和时间转换格式.自己总结两个方式就行转换. 一,new Date(时间戳).for ...

  8. 爱,死亡和机器人 第十四集 齐马蓝 中文字幕(Python处理utf8文件获取想要的内容)

    处理代码 file = "a.srt" fi = open(file, mode='r') a = fi.readline() i = 1 while len(str(a)) != ...

  9. 【Oracle】搭建DG(DataGuard)

    操作系统:OEL 5.6 Oracle 版本:11.2.0.4.0 DataGuard规划说明 DATABASE_ROLE DB_NAME IPADDR Primary lgr 192.168.10. ...

  10. MySQL数据库的使用流程,代码解释+Hibernate连接数据库

    数据库的使用流程: 1.注册驱动: 2.用DriverManager.getConnection方法获得连接对象con: A方法:  3.用连接对象的createStatement()方法,获得可以执 ...