Altough Skipping the class is happy, the new term still can drive luras anxious which is of course because of the tests! Luras became worried as she wanted to skip the class, as well as to attend the BestCoder and also to prepare for tests at the same time.
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.
InputThe first line is an integer T which indicates the case number.
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 <= 100000OutputAs for each case, you need to output a single line.
there should be 1 integer in the line which represents the number of
the counting way of 4-sheep-sequence before luras’s sleep.Sample Input
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
Sample Output8
0
2
题目大意:FJUTOJ上面有中文题,题目大意就不解释了,说一下第一个样例的意思
2 2 4
1 1
1 2
2 1
2 2
两个男两个女,4种关系:男一与女一朋友,男一与女二朋友等等;
然后计算一下有多少种可以这四人的朋友关系,例如1-3-2-4,,1-4-2-3,3-2-4-1,3-1-4-2……….共八种。
思路:将两人放中间他们两边的朋友有多少?用数组标记一下就可以了;
按照数组模拟出来的还要记住要初始化数组,数组还不能开的太大不然memset函数容易超时
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<time.h> 3 #include<stdlib.h> 4 #include<string.h> 5 6 int a[100100],b[100010]; 7 int vis1[1000010],vis2[100010]; 8 9 int main() 10 { 11 int T; 12 scanf("%d",&T); 13 while(T--) 14 { 15 memset(vis1,0,sizeof(vis1)); 16 memset(vis2,0,sizeof(vis2)); 17 int n,m,k; 18 scanf("%d%d%d",&n,&m,&k); 19 for(int i=0;i<k;i++) 20 { 21 scanf("%d%d",&a[i],&b[i]); 22 vis1[a[i]]++; 23 vis2[b[i]]++; 24 } 25 long long sum=0; 26 for(int i=0;i<k;i++) 27 { 28 sum+=(vis1[a[i]]-1)*(vis2[b[i]]-1); 29 } 30 printf("%lld ",sum*2); 31 } 32 return 0; 33 }