Title Link: http://acdream.info/problem?pid=1213
There are many mathematical knowledge involved, including the matrix transpose, matrix multiplication, correlation matrix ....
The first is directly in accordance with the concept of the results of the MLE, the MLE code is as follows
#include <cstdio> #include <iostream> #include <sstream> #include <cstdlib> #include < cstring> #include <string> #include <climits> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <set> #include <map>using namespace Std;int n,m;int A[10005][5],v[10005][10005],v1[10005][10005];int Main () {int i,j; while (~SCANF ("%d%d", &n,&m)) {memset (v,0,sizeof (v)); memset (v1,0,sizeof (v1)); for (i=0;i<m;i++) for (j=0;j<2;j++) scanf ("%d", &a[i][j]); for (i=0;i<m;i++) v[a[i][0]-1][a[i][1]-1]=v[a[i][1]-1][a[i][0]-1]=1; for (i=0;i<n;i++) for (j=0;j<m;j++) v1[j][i]=v[i][j]; int sum=0,b=0,k=m; while (k--) {for (i=0;i<n;i++) {int c=0; for (j=0;j<m;j++) {SUM+=V[B][C++]*V1[j] [i]; }} b++; } printf ("%d\n", sum); } return 0;}
On the Internet to see other people's solution to get ideas, the following is the AC code
#include <cstdio> #include <iostream> #include <sstream> #include <cstdlib> #include < cstring> #include <string> #include <climits> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <set> #include <map>using namespace Std;int n,m;int A[100005];int Main () { int i,j; while (~SCANF ("%d%d", &n,&m)) { int u,v; memset (a,0,sizeof (v)); for (I=1; i<=m; i++) { scanf ("%d%d", &u,&v); a[u]++; a[v]++; } Long long sum=0; for (I=1; i<=n; i++) sum+=a[i]*a[i]; printf ("%lld\n", sum); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Acdream 1213 matrix multiplication (matrix multiplication)