解题报告:一开始不知道ATA的意思,后来才知道原来是转置矩阵乘以原来的矩阵。这题说起来比较麻烦就不说了,直接上代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 int A[100005]; 6 7 int main() 8 { 9 int T,n,m; 10 scanf("%d",&T); 11 while(T--) 12 { 13 scanf("%d%d",&n,&m); 14 int d = m,x,y; 15 int sum = 0; 16 memset(A,0,sizeof(A)); 17 while(m--) 18 { 19 scanf("%d%d",&x,&y); 20 A[x]++,A[y]++; 21 } 22 for(int i = 1;i<=n;++i) 23 { 24 A[i]--; 25 sum += ((1 + A[i])*A[i] / 2); 26 } 27 sum *= 2; 28 sum += (2*d); 29 printf("%d ",sum); 30 if(T) printf(" "); 31 } 32 return 0; 33 } 34