bc#92 B

Source: Internet
Author: User

School skipping class is happy, however, there are things that let er meow, that is, of course, the exam! This can be nasty, both skipping classes and want to play BC and prepare for the exam, uh meow. Uh meow in order to prepare for the exam no time to brush questions, want to play BC and do not want to fall points, had to resort to BCround92 Snowy_smile, let him say something ~~>_<~~. Snowy_smile really no way, but embarrassed by the question, had to tell ER Meow, the priority is a good rest. "If you fall asleep according to the following method, then the next day will definitely not fall on the field of BC-imagine a boundless, vast expanse of the green grassland, the grassland lived a flock of sheep, including n silent male sheep and M only tears female sheep, between the male and female sheep, there is a K friend relationship. Now you can start with any sheep and count along with your friends. If you can count 4 different sheep in succession, you will be able to sleep more than 99% sheep. "Ah Meow after hearing very shocked, but she still obedient to count down, sure enough, count to the 4th sheep fell asleep, and a breath of sleep over the head, successfully missed the second day of the Bestcoder, really will not fall on the BC field!" However, you, but there is no such good luck, since you see this second question, nature has generally been submitted, has been unable to turn back. In the face of "No AC This problem may fall" dilemma you, need to say, uh meow before going to sleep how many different number of sheep sequence. That is, the output "a-b-c-d" Such a sequence of the number of scenarios, to meet a-B, B-c, c-d is a friend relationship and A, B., C, D are different.
Enter a description
The first line of input data group T for each group of data, the first line has three integers n, m, K, indicating that n only male sheep number is 1~n,m only female sheep number respectively is 1~m, and there are K friends relationship. Next the K line is given, each row gives two number x Y, indicating that the first male sheep and the first female sheep are friends. Data assurance-not to give a duplicate friend Relationship 1 <= T <= 1000 for 30% data, 1 <= N, m, K <= 100 for 99% data, 1 <= N, m, K <= 1000 for 100% data, 1 < = N, m, K <= 100000
Output description
For each set of data, the output line contains an integer that indicates the number of scenarios in which 4 sheep can be counted before bedtime.
Input sample
(in order to facilitate reading, the sample input will add an additional line of blank lines between data sets) 32 2 41 11 22 12 23 1 31 12 13 13 3 31 12 12 2
Output sample
802
Hint
First set of examples: (B1-G1-B2-G2) (B1-G2-B2-G1) (B2-G1-B1-G2) (B2-G2-B1-G1) (G1-B1-G2-B2) (G1-B2-G2-B1) (G2-B1-G1-B2) (G2-B2-G1-B1) A total of 8 legal sequences
1#include <iostream>2#include <cstdio>3#include <vector>4 using namespacestd;5 6vector<int> frm[100010];7 intw[100010];8 9 intMain ()Ten { One     intT; Ascanf"%d",&t); -      while(t--) -     { the         intn,m,k; -scanf"%d%d%d",&n,&m,&k); -          for(intI=max (n,m); i>=1; i--) -Frm[i].clear (), w[i]=0; +          for(intI=1; i<=k;i++) -         { +             intx, y; Ascanf"%d%d",&x,&y); at frm[x].push_back (y); -w[y]++; -         } -         Long Longans=0; -          for(intI=1; i<=n;i++) -         { in             Long LongP=frm[i].size ()-1; -              for(vector<int>::iterator It=frm[i].begin (); It<frm[i].end (); it++) to             { +ans+= (w[it]-1)*p; -             } the         } *ans*=2; $printf"%lld\n", ans);Panax Notoginseng     } -     return 0; the}

bc#92 B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.