solution:
N is anti difficult , considering the number of variegated triangle, each point can be considered the object count.
Namely: Total - heteroaryl pure =
Total: C [n-] [. 3] = n-/ (. 3 * (. 3-n-)!!) = N-! (N--. 1) (n--2) /. 6;
杂: (sigma r [i] * b [i]) / 2
Heteroaryl triangle is calculated:
Each point has a number of edges of the color 0 and the number of the x y 1-edge color,
it produces a triangular variegated x * y is one, but it will be repeated, imagine a variegated triangle, are two points are counted once, so that repeatability is 2, last / 2 like.
const int N = 1010;
int n;
int b[N],r[N];
int main(){
int T;rd(T);
while(T--){
mem(b,0),mem(r,0);//初始化
rd(n);
rep(i,1,n-1){
rep(j,i+1,n){
int x;rd(x);
if(x==0)b[i]++,b[j]++;
else if(x==1)r[i]++,r[j]++;
}
}
int sum=0;
rep(i,1,n)sum+=b[i]*r[i];
printf("%lld\n",n*(n-1)*(n-2)/6-sum/2);
}
return 0;
}