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. Android之怎样更改获取焦点的先后顺序

    在组件中增加<requestFocus />能够首先获得焦点 以TextView为例: 例如以下: <TextView         android:layout_width=&q ...

  2. gephi——怎样上传节点表格而且为节点设定颜色类型

    使用gephi过程中出现两个问题: 一.节点编号不安给定的属性(Nodes)编号,而是莫名其妙地从1w+開始 解决:数据列名中需包括 id.则默觉得节点编号 二.怎样在上传的数据中指定节点颜色 须要一 ...

  3. cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第0步---知识点总结&amp;效果预览&amp;设计思路

    /* 说明: **1.本次游戏实例是<cocos2d-x游戏开发之旅>上的最后一个游戏.这里用3.0重写并做下笔记 **2.我也问过木头本人啦,他说:随便写.第一别全然照搬代码:第二能够说 ...

  4. Android开机logo修改方法 【转】

    本文转载自:http://blog.csdn.net/qq258711519/article/details/7766303 一体机平台开机logo修改方法 1:修改Kernel中的Logo: 若是要 ...

  5. 软件开发 —— 极限编程(XP:Extreme Programming)

    1. 软件开发的基本概念 软件开发的过程是:需求分析.设计.编码和测试. 2. 极限编程基本内涵 极限编程是一个轻量级的.灵巧的软件开发方法:同时它也是一个非常严谨和周密的方法. 它的基础和价值观是交 ...

  6. 深入Session

    早上考虑Spring MVC和Structs2项目共用时看到一个问题,如何保持session一致?Session是怎么样被服务器处理的呢,Spring MVC中是如何封装处理Session并在不同请求 ...

  7. solaris&nbsp;10&nbsp;关闭ftp、telnet

    安装solaris10,启动后发现找不到ftp.telnet的关闭方法, 管理命令 svcadm(服务状态管理,启动.停止等) # svcs 查看当前所有的服务状态,可以使用|管道符重定向作更个性化的 ...

  8. [Javascript] HTML5 地理位置定位(HTML5 Geolocation)原理及应用

    地理位置(Geolocation)是 HTML5 的重要特性之一,提供了确定用户位置的功能,借助这个特性能够开发基于位置信息的应用.今天这篇文章向大家介绍一下 HTML5 地理位置定位的基本原理及各个 ...

  9. [Swift]注册并购买加入Apple开发者计划。提示: “你的支付授权失败。请核对你的信息并重试,或尝试其他支付方式。请联系你的银行”

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  10. vs添加浏览器

    点击桌面谷歌图标,查看属性,赋值全部地址 在vs中,直接添加,把地址复制进去就ok了