给一个无向图,如果第i个点连接第j条边,那么mat[i][j]=1,否则mat[i][j]=0。

求mat的转置乘以本身得到的矩阵每个位置的和是多少?

理解矩阵的意义就比较好做了。

mat[i][j]表示i点可以连接到j边,转置后相乘的意义是第i边和第j边有公共点。

这样,我们只需要统计每个点的度数,这样我们就知道有多少组这样有公共点的边了,也就是最终的答案了。

如果是mat乘以mat的转置,思考的方法也是一样的。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 100100
typedef long long ll;
using namespace std; int d[maxn],n,m,U,V;
ll ans; int main()
{
scanf("%d%d",&n,&m);
ans=m+m;
while (m--){
scanf("%d%d",&U,&V);
d[U]++,d[V]++;
}
for (int i=; i<=n; i++)
ans+=ll(d[i])*(d[i]-);
cout<<ans<<endl;
return ;
}

SGU196_Matrix Multiplication的更多相关文章

  1. POJ2505 A multiplication game[博弈论]

    A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6028   Accepted:  ...

  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. Booth Multiplication Algorithm [ASM-MIPS]

    A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...

  6. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

  7. hdu4920 Matrix multiplication 模3矩阵乘法

    hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  8. poj 1651 Multiplication Puzzle (区间dp)

    题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...

  9. 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

    题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...

随机推荐

  1. java 线程的优先级

    //线程的优先级 //线程1 class xc1 implements Runnable{ public void run(){ for(int i=0;i<20;i++){ System.ou ...

  2. eclipse 代码自动提示

    从Window -> preferences -> Java -> Editor -> Content assist -> Auto-Activation下,我们可以在& ...

  3. protoc 命令参数

    protoc 命令的获得 源码在 https://github.com/google/protobuf , 如果不想自己编译获得最新版本,则可以下载官方编译好的各个平台的,下载地址:https://g ...

  4. RabbitMQ(二)

    一.启用 rabbitmq_management 插件(官网提供的 web 版管理工具) cd /usr/sbin rabbitmq-plugins enable rabbitmq_managemen ...

  5. 69. Letter Combinations of a Phone Number

    Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations ...

  6. dijkstra

    寻找从源结点到其他点之间的最短距离. 把给出的结点分成两组,一组a刚开始为空,另一组b为全部节点,dis[i]记录从源点到i结点的距离,同样当所有操作结束后dis[i]就是到达源点的最短距离啦,每次更 ...

  7. org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported

    1:先上控制台报错信息 org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not ...

  8. python之I/O多路复用

         python  IO多路复用 一.多路复用概念: 监听多个描述符(文件描述符(windows下暂不支持).网络描述符)的状态,如果描述符状态改变 则会被内核修改标志位,进而被进程获取进而进行 ...

  9. openldap权限sudo

    http://pig.made-it.com/ldap-sudoers.html https://www.lisenet.com/2015/convert-openldap-schema-to-ldi ...

  10. HTML中常用meta整理

    < meta > 元素 定义 meta标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其 ...