HUST上8ms过。
后来发现有问题,莫名其妙的过了。
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
bool cmp(int a,int b)
{
if(a>b)
return true;
else
return false;
}
int main()
{
int t,i,j,n,m;
int temp,x;
int row[1001],col[1001];
scanf("%d",&t);
while(t--)
{
temp=0;
scanf("%d%d",&n,&m);
int cnt = 0;
for(i=0;i<m;i++)
scanf("%d%d",&row[i],&col[i]);
sort(row,row+m,cmp);
sort(col,col+m,cmp);
for(i=0;i<m-1;i++)
if(row[i]==row[i+1])
cnt--;
x=col[0];
for (i = 0; i < m; i++)
{
if (col[i]==x)
{
temp++;
}
else
{
cnt+=temp*temp;
temp=0;
x=col[i];
i--;
}
}
cnt+=temp*temp;
printf("%d\n",cnt);
}
return 0;
}