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. 安卓实现序列化之Parcelable接口

    安卓实现序列化之Parcelable接口 1.实现序列化的方法: Android中实现序列化有两个选择:一是实现Serializable接口(是JavaSE本身就支持的) .一是实现Parcelabl ...

  2. objective-c 中数据类型之四 字典(NSDictionary)

    // 1. 字典初始化.赋值方式1 NSMutableDictionary *m_dictionary = [[NSMutableDictionary alloc] initWithCapacity: ...

  3. ubuntu下创建第一个rails应用程序

    一.创建一个新的应用程序 在控制台输入 > rails new  demo create create README.rdoc create Rakefile create config.ru ...

  4. java 10000的阶乘

    package test; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import ...

  5. JavaScript:Browser 对象

    ylbtech-JavaScript:Browser 对象 1.  Window 对象返回顶部 1. Window 对象 Window 对象 Window 对象表示浏览器中打开的窗口. 如果文档包含框 ...

  6. 软件-集成开发环境:IDE

    ylbtech-软件-集成开发环境:IDE 集成开发环境(IDE,Integrated Development Environment )是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器. ...

  7. php获取uniqid

    md5(uniqid(microtime(true),true))

  8. Juniper交换机维护

    Juniper交换机维护操作之一: 1.1   交换机启动和关闭 1.1.1   重新启动 1.   使用具有足够权限的用户名和密码登陆CLI命令行界面. 2.   在提示符下输入下面的命令: use ...

  9. systemd实践: 依据情况自动重启服务

    systemd服务异常自动重启很好用,但有的时候希望某些服务只在特定情况下进行重启,其他时候不要自动重启(比如OOM,需要人工介入). 本文抛砖引玉,旨在能够让读者对systemd的重启机制有一定了解 ...

  10. WEBGL学习笔记(七):实践练手1-飞行类小游戏之游戏控制

    接上一节,游戏控制首先要解决的就是碰撞检测了 这里用到了学习笔记(三)射线检测的内容了 以鸟为射线原点,向前.上.下分别发射3个射线,射线的长度较短大概为10~30. 根据上一节场景的建设,我把y轴设 ...