However, As the result of preparing for tests, luras had no time to practice programing. She didn't want to lose her rating after attending BC. In the end, she found BCround92's writer snowy_smile for help, asking him to leak her something.
Snowy_smile wanted to help while not leaking the problems. He told luras, the best thing to do is to take a good rest according to the following instructions first.
"Imagine you are on the endless grassland where there are a group of sheep. And n sheep of them are silent boy-sheep while m sheep are crying girl-sheep. And there are k friend-relationships between the boy-sheep and girl-sheep.Now You can start from any sheep, keep counting along the friend relationship. If you can count 4 different sheep, you will exceed 99% sheep-counters and fall asleep."
Hearing of the strange instructions, luras got very shocked. Still, she kept counting. Sure enough, she fell asleep after counting 4 different sheep immediately. And, she overslept and missed the BestCoder in the next day. At a result, she made it that not losing her rating in the BCround92!!!
However, you don't have the same good luck as her. Since you have seen the 2nd problem, you are possible to have submitted the 1st problem and you can't go back.
So, you have got into an awkward position. If you don't AC this problem, your rating might fall down.
You question is here, please, can you tell that how many different 4-sheep-counting way luras might have before her sleep?
In another word, you need to print the number of the "A-B-C-D" sequence, where A-B, B-C, C-D are friends and A,B,C,D are different.
and as for each case, there are 3 integers in the first line which indicate boy-sheep-number, girl-sheep-number and friend-realationship-number respectively.
Then there are k lines with 2 integers x and y in each line, which means the x-th boy-sheep and the y-th girl-sheep are friends.
It is guaranteed that——
There will not be multiple same relationships.
1 <= T <= 1000
for 30% cases, 1 <= n, m, k <= 100
for 99% cases, 1 <= n, m, k <= 1000
for 100% cases, 1 <= n, m, k <= 100000
there should be 1 integer in the line which represents the number of the counting way of 4-sheep-sequence before luras's sleep.
3 2 2 4 1 1 1 2 2 1 2 2 3 1 3 1 1 2 1 3 1 3 3 3 1 1 2 1 2 2
8 0 2
本文大体意思就是男-女-男-女或者反过来排序
是一道思维开阔的题目
嗯主要的想法就是 把输入的人先算出他们各有多少的朋友
其次就是把他们当作中间的人一次算出两旁都有多少朋友这样子会比较简便
到最后直接*2因为是可以反过来的
C++代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long int x[100005],y[100005];
long long int nx[100005],ny[100005];
int main()
{
long long int n;
scanf("%lld",&n);
long long int a,b,k;
while(n--)
{
memset(nx,0,sizeof(nx));
memset(ny,0,sizeof(ny));
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
scanf("%lld%lld%lld",&a,&b,&k);
for(int i=1;i<=k;i++)
{
scanf("%lld%lld",&x[i],&y[i]);
nx[x[i]]++;
ny[y[i]]++;
}
long long int sum=0;
for(int i=1;i<=k;i++)
{
sum=sum+(nx[x[i]]-1)*(ny[y[i]]-1);
}
printf("%lld\n",sum*2);
}
return 0;
}