ACdream 1213 Matrix Multiplication

Matrix Multiplication

Time Limit: 2000/1000MS (Java/Others)  Memory Limit: 128000/64000KB (Java/Others)
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 = {a i,j}, such that a i,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 A TA.
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 4
1 2
1 3
2 3
2 4
Sample Output
18
Source
Andrew Stankevich Contest 1
Manager

题意:给一个无向图,设这个图的关联矩阵为A。然后计算ATA这个矩阵中,所有元素的和。



思路:观察关联矩阵,对于每条边的两个顶点,这条边对结果的贡献是这两个顶点的度,所以只需要扫描每条边,然后加上出现的顶点的度就可以了。

#include <cstring>
#include <cstdio>
typedef long long LL;
const int mx=100010;
int edge[mx][2];
int cnt[mx];

int main() {
    int n,m;
    while(~scanf("%d%d",&n,&m)) {
        memset(cnt,0,sizeof(cnt));
        for(int i=1; i<=m; i++) {
            int u,v;
            scanf("%d%d",&u,&v);
            edge[i][0]=u;
            edge[i][1]=v;
            cnt[u]++;
            cnt[v]++;
        }
        LL ans=0;
        for(int i=1; i<=m; i++) {
            ans+=cnt[edge[i][0]];
            ans+=cnt[edge[i][1]];
        }
        printf("%lld\n",ans);
    }
    return 0;
}



"sgmediation.zip" 是一个包含 UCLA(加利福尼亚大学洛杉矶分校)开发的 sgmediation 插件的压缩包。该插件专为统计分析软件 Stata 设计,用于进行中介效应分析。在社会科学、心理学、市场营销等领域,中介效应分析是一种关键的统计方法,它帮助研究人员探究变量之间的因果关系,尤其是中间变量如何影响因变量与自变量之间的关系。Stata 是一款广泛使用的统计分析软件,具备众多命令和用户编写的程序来拓展其功能,sgmediation 插件便是其中之一。它能让用户在 Stata 中轻松开展中介效应分析,无需编写复杂代码。 下载并解压 "sgmediation.zip" 后,需将解压得到的 "sgmediation" 文件移至 Stata 的 ado 目录结构中。ado(ado 目录并非“adolescent data organization”缩写,而是 Stata 的自定义命令存放目录)目录是 Stata 存放自定义命令的地方,应将文件放置于 "ado\base\s" 子目录下。这样,Stata 启动时会自动加载该目录下的所有 ado 文件,使 "sgmediation" 命令在 Stata 命令行中可用。 使用 sgmediation 插件的步骤如下:1. 安装插件:将解压后的 "sgmediation" 文件放入 Stata 的 ado 目录。如果 Stata 安装路径是 C:\Program Files\Stata\ado\base,则需将文件复制到 C:\Program Files\Stata\ado\base\s。2. 启动 Stata:打开 Stata,确保软件已更新至最新版本,以便识别新添加的 ado 文件。3. 加载插件:启动 Stata 后,在命令行输入 ado update sgmediation,以确保插件已加载并更新至最新版本。4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值