传送门:​​点击打开链接​

题意:将一个矩阵A先转置,然后再与原A矩阵相乘,求最后得到的矩阵中的数字之和

思路:刚开始没看懂题目,,,随便写几个矩阵A,然后倒置后相乘找规律,一下子就能发现规律,最后的答案等于每一行数字之和的平方之和

#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int>PII;

const int MX = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int cnt[MX];
int main() {
int n, m;//FIN;
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);
if(u != v) {
cnt[u]++; cnt[v]++;
} else cnt[u]++;
}

LL ans = 0;
for(int i = 1; i <= n; i++) {
ans += (LL)cnt[i] * cnt[i];
}
printf("%lld\n", ans);
}
return 0;
}