ZOJ 2316 Matrix Multiplication
Matrix Multiplication
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
#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的更多相关文章
- zoj 2316 Matrix Multiplication 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2316 题目意思:有 N 个 点,M 条 边.需要构造一个N * ...
- 【数学】Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total S ...
- hdu 4920 Matrix multiplication bitset优化常数
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- 矩阵乘法 --- hdu 4920 : Matrix multiplication
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- hdu4920 Matrix multiplication 模3矩阵乘法
hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- acdeream Matrix Multiplication
D - Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- Matrix multiplication hdu4920
Problem Description Given two matrices A and B of size n×n, find the product of them. bobo hates big ...
- HDU-4920 Matrix multiplication
矩阵相乘,采用一行的去访问,比采用一列访问时间更短,根据数组是一行去储存的.神奇小代码. Matrix multiplication Time Limit: 4000/2000 MS (Java/Ot ...
随机推荐
- 初探BurpSuite
BurpSuite这套渗透软件.或者已经能够说是渗透攻击平台了吧,玩的好.确实非常方便. 就像是玩英雄联盟的ADC,一開始玩VN.感觉非常难上手,玩多了肯定会爱上VN(啊,貌似提到了什么奇怪的东西). ...
- uva 1555 Garland
题意:有n个灯笼.第一个的高度是A,最后一个是B.灯笼的关系给出.并要求每一个灯笼的高度是非负数的.求最低的B 思路:推出公式:H[i]=2*H[i-1]+2-H[i-2],然后枚举H[2],在知道H ...
- POJ3463 Sightseeing
题目大意:求两点间最短路与长度为最短路长度+1的路径的条数之和. 方法1:最短路径+DP 首先求出ST间最短路径,然后根据递归式记忆化搜索(因此还要构造反向图). 我们知道到达终点的路径长度最长为ma ...
- J2EE7与Servlet3.x
J2EE7结构图 JWS:即Java Web Service,指与webservice相关的JavaEE技术部分,webservice是一种基于XML的独立的.跨平台的.互操作的应用程序,XML又包含 ...
- [转载]RouteOS安装设置
原文地址:RouteOS安装设置作者:抟鹏追梦 RouteOS2.7.4可以将一台普通的PC机变成一台专业的路由器,高到ISP的核心路器/认证网关-因为它功能强大稳定,低到家庭网关防火墙-因为它免费. ...
- Serializable-源码分析
package java.io; public interface Serializable { } 代码很简单,功能也很简单,对象通过这个接口来实现序列化和反序列的.下面来看看小例子. import ...
- 如何让音频跟视频在ios跟android上自动播放
如何让音频跟视频在ios跟android上自动播放 <audio autoplay ><source src="audio/alarm1.mp3" type=&q ...
- Linux Shell Scripting Cookbook 读书笔记 6
wget,curl, tar, rsync wget ftp://example.com/somefile.img -t 5 -O download.img -o log -t表示重试的次数 -O指定 ...
- 关于CI中的MVC以及扩展CI中的控制器
MVC是一种设计模式模式,M(模型)—V(视图)—C(控制器): MVC的核心思想是强制开发者在进行项目开发时,将数据的输入,处理,输出分开编写: 1.入口文件:该文件是唯一一个给浏览器直接请求的脚本 ...
- (转载) android studio library生成jar包和aar的方法总结
android studio library生成jar包和aar的方法总结 标签: android学习文档jar和aar的使用与生成gradle 2016-11-25 10:39 1782人阅读 评论 ...