ZOJ 2316 Matrix Multiplication
来源:互联网 发布:mac下载软件怎么删除 编辑:程序博客网 时间:2024/05/28 05:15
Description
Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this graph is N * M matrix A = {a ij}, such that a ij 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 A TA.
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
矩阵乘法,知道算法就简单了。
#include<stdio.h>#include<map>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int maxn=10005;int T,a[maxn],x,y,n,m;long long ans;int main(){while (~scanf("%d",&T)){while (T--){memset(a,0,sizeof(a));scanf("%d%d",&n,&m);for (int i=0;i<m;i++){scanf("%d%d",&x,&y);a[x]++;a[y]++;}ans=0;for (int i=1;i<=n;i++)ans+=(long long)(a[i])*a[i];cout<<ans<<endl;if (T) printf("\n");}}return 0;}
- ZOJ 2316 Matrix Multiplication
- Matrix Multiplication(zoj 2316)
- zoj 2316 Matrix Multiplication
- zoj 2316 Matrix Multiplication(2-D)
- zoj - 1094 - Matrix Chain Multiplication
- zoj-1094-Matrix Chain Multiplication
- zoj 1094 Matrix Chain Multiplication
- ZOJ 1094 Matrix Chain Multiplication
- ZOJ 1094 Matrix Chain Multiplication
- ZOJ-1094-Matrix Chain Multiplication
- HUT_ACM #1 D Matrix Multiplication(ZOJ-2316)
- ZOJ-1094,POJ-2246 Matrix Chain Multiplication
- zoj 1094 poj 2246 Matrix Chain Multiplication(堆栈)
- UVa 442 - Matrix Chain Multiplication(zoj 1094)
- POJ 2246/ ZOJ 1094 : Matrix Chain Multiplication - 矩阵相乘,模拟
- Matrix Multiplication
- Matrix Multiplication
- Matrix Multiplication
- 基础知识
- javascript 中的innerHTML的用法
- SNMP-简单网络管理协议简介
- 小谈ONLINE-GAME服务器端设计(1、2)
- 线程本地存储:pthread_key_t
- ZOJ 2316 Matrix Multiplication
- Redis + EJB 实现缓存(二)
- 颠倒的价牌——第四届蓝桥杯省赛C语言A组第4题
- [IT]C/S自动升级程序原理
- 小谈ONLINE-GAME服务器端设计(3)
- 小谈ONLINE-GAME服务器端设计(4)
- 使用CBitmapButton类创建位图按钮
- 辛星整理Linux中查看版本信息的若干方法
- ZOJ 2315 New Year Bonus Grant