傳送門
題意:
思路:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll vis[200010];
ll d[200010];
vector<ll>a[200010];
int main()
{
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(int i = 1; i <= n; i++)
{
ll num,leve;
scanf("%lld%lld",&num,&leve);
a[num].push_back(leve);
vis[leve]++;
}
int cnt = 0;
ll ans = n*(n-1)*(n-2)/6;
for(int i = 1; i <= n; i++)
{
if(a[i].size())d[++cnt] = i;
}
ll k = 0;
for(int i = 1; i <= cnt; i++)
{
k = 0;
for(int j = 0; j < a[d[i]].size(); j++)
{
k += (vis[a[d[i]][j]]-1)*(a[d[i]].size()-1);
}
ans-=k;
}
printf("%lld\n",ans);
for(int i = 1; i <= n; i++)a[i].clear(),d[i] = 0,vis[i] = 0;
}
}