linkkkk
题意:
给出个人,每个人有
两种属性,保证没有两个人的
属性都相同。
问能够选出三个人满足以下条件之一的方案数:
- 三个人的
属性各不相同
- 三个人的
属性各不相同
思路:
逆向思维,合法的方案等于总方案数减去不合法的方案数。
总方案数相当于
不合法的方案数如何计算呢。
先处理出表示属性
出现的次数,同理,也处理出
假设有三个人,此时
的
属性和
的
属性一样,
的
属性和
的
属性一样,这样的方案数有
是因为要将本身去掉
代码:
// Problem: D. Training Session
// Contest: Codeforces - Educational Codeforces Round 115 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1598/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
#define I_int ll
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
#define read read()
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define dep(i, a, b) for(int i=(a);i>=(b);--i)
ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
const int maxn=2e5+7,maxm=1e6+7,mod=1e9+7;
ll a[maxn],b[maxn],cnta[maxn],cntb[maxn],n;
void solve()
{
ll n=read;
rep(i,1,n) cnta[i]=cntb[i]=0;
rep(i,1,n) a[i]=read,b[i]=read,cnta[a[i]]++,cntb[b[i]]++;
ll ans=n*(n-1)*(n-2)/6;
rep(i,1,n)
ans=ans-(cnta[a[i]]-1)*(cntb[b[i]]-1);
cout<<ans<<endl;
}
int main(){
int _=read;
while(_--) solve();
return 0;
}