Acdream 1213——Matrix Multiplication
来源:互联网 发布:怎么用iwatch解锁mac 编辑:程序博客网 时间:2024/06/05 02:39
Matrix Multiplication
Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
SubmitStatisticNext Problem
Problem Description
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 = {ai,j}, such that ai,j 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.
Input
The first line of the input file contains two integer numbers — N and M (2 ≤ N ≤ 10 000, 1 ≤ M ≤100 000). Then 2*M 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
4 41 21 32 32 4
Sample Output
18
Source
Andrew Stankevich Contest 1
Manager
mathlover
显然矩阵太大无法存, 所以要找规律,这题特殊在矩阵是关联矩阵,看图
所以,C[i][j]可以看成是第k行里任意两个元素相乘的和
由于这里的矩阵是01矩阵,所以可以只考虑1 * 1,显然,第k行的和就是点k的度
比如第k行为 1 0 1 1,任意2个元素相乘的和是9,deg[k]^2 == 9
显然矩阵太大无法存, 所以要找规律,这题特殊在矩阵是关联矩阵,看图
所以,C[i][j]可以看成是第k行里任意两个元素相乘的和
由于这里的矩阵是01矩阵,所以可以只考虑1 * 1,显然,第k行的和就是点k的度
比如第k行为 1 0 1 1,任意2个元素相乘的和是9,deg[k]^2 == 9
#include<map> #include<set> #include<list> #include<stack> #include<queue> #include<vector> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std;int deg[10010];int main(){int n, m;while (~scanf("%d%d", &n, &m)){memset( deg, 0, sizeof(deg) );int u, v;for (int i = 1; i <= m; i++){scanf("%d%d", &u, &v);deg[u]++;deg[v]++;}long long ans = 0;for (int i = 1; i <= n; i++){ans += (long long)(deg[i] * deg[i]);}printf("%lld\n", ans);}return 0;}
0 0
- Acdream 1213——Matrix Multiplication
- ACdream 1213 Matrix Multiplication
- ACdream 1213 Matrix Multiplication
- ACdream 1213 Matrix Multiplication(矩阵乘法)
- ACdream 1213 Matrix Multiplication(矩阵相乘)
- ACdream 1213 Matrix Multiplication【水题 、 找规律】
- ACdream 1213 Matrix Multiplication 其实是一道思维题
- ZOJ2316——Matrix Multiplication
- hdu 4920——Matrix multiplication
- POJ 3318 Matrix Multiplication【矩阵相乘——随机化检测】
- Problem 039——UVa 442 - Matrix Chain Multiplication
- UV 442 Matrix Chain Multiplication——思路题
- poj3318——Matrix Multiplication(随机化算法)
- uva442(Matrix Chain Multiplication)—线性表
- 杭电acm—1082 Matrix Chain Multiplication
- Matrix Multiplication
- Matrix Multiplication
- Matrix Multiplication
- DFS HDU 1364
- BZOJ 1507 NOI2003 Editor Splay
- 将CString类型数据保存到txt文本文件中(Unicode下无乱码)
- mysql连接数据库的优化(一次连接多次使用)
- 为什么使用apache-httpclient而不是jdk-urlconnection
- Acdream 1213——Matrix Multiplication
- Python 抓取网页学习系列之一(网页编码格式)
- 取得套接字选项
- Servlet实现文件的下载
- Code::Blocks安装流程
- 我所读的书籍
- zoj 3229 有源汇上下界最大流
- HDU 1068 Girls and Boys 最大独立集 二分图匹配
- hdu 4223 Dynamic Programming? (dp)