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 ...
随机推荐
- poj2299--归并排序求逆序数
/** \brief poj2299 * * \param date 2014/8/5 * \param state AC * \return memory 4640K time 3250ms ...
- iWatch报错: Authorization request cancled
iWatch报错: Optional (Error Domin = com.apple.healthkit Code = 5 "Autherization request canceled& ...
- 齐头并进完成任务——Java多线程(一)
多线程(Multithread)指的是在单个进程中同时运行多个不同的线程,执行不同的任务.多线程意味着一个程序的多行语句块并发执行. 一.实现多线程 1.通过继承Thread类实现多线程. Threa ...
- Android与JS互相调用以及注意
近期项目中常常使用Html5而Android与JS调用常常会用到,这里记录一下,測试系统5.0以上. 这里先贴一下源代码 Activity: package jwzhangjie.com.webvie ...
- 在android中读写文件
在android中读写文件 android中只有一个盘,正斜杠/代表根目录. 我们常见的SDK的位置为:/mnt/sdcard 两种最常见的数据存储方式: 一.内存 二.本地 1.手机内部存储 2.外 ...
- 杂项:DS(目录服务)
ylbtech-杂项:DS(目录服务) 1.返回顶部 1. DS(目录服务). 目录服务管理概述: 目录服务是扩展计算机系统中最重要的组件之一.虽然用户和管理通常不知道他们感兴趣对象的确切名称,但他们 ...
- SwiftUI 官方教程(八)
8. 动态生成预览 接下来,我们会在 LandmarkList_Previews 中添加代码以在不同的设备尺寸上渲染列表.默认情况下,预览会以当前的 scheme 中设备的大小进行渲染.我们可以通过调 ...
- python基本数据类型之元祖tuple
元祖tuple 是对列表的二次加工,书写格式为括号(),里面放元素 元组的一级元素不可被修改,且不能被增加和删除 一般写元组的时候,推荐在最后加入逗号, 能加则加 创建元组 ? 1 tu = (11 ...
- vue2.0项目中使用Ueditor富文本编辑器应用中出现的问题
1.如何设置config中的内容 readonly:true,//只读模式wordCount:false,//是否开启字数统计enableAutoSave: false,//自动保存功能 重点:ena ...
- WEB笔记-1、HTML 标记与文档结构
1.HTML 标记与文档结构 1.1 块级(block)和行内(inline)标签 块级标签 <h1>-<h6> : 6级标签,h1表示最重要(h1 不仅仅是最大最突出 ...