sgu 196 Matrix Multiplication
题意:给出的图连成矩阵,问转置矩阵和原矩阵乘积后的元素和。
随便拿个矩阵模拟一下会发现,结果就是各点度的平方和。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #define mkp make_pair using namespace std; const double EPS=1e-8; typedef long long lon; const int SZ=20010,INF=0x7FFFFFFF; int arr[SZ]; int main() { //std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) { int n,m; cin>>n>>m; for(int i=0;i<2*m;++i) { int tmp; cin>>tmp; ++arr[tmp]; } lon res=0; for(int i=1;i<=n;++i) { res+=arr[i]*arr[i]; } cout<<res<<endl; } return 0; }