日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 6016】Count the Sheep (思维,类似二分图)

發(fā)布時間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 6016】Count the Sheep (思维,类似二分图) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

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.

Input

The 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 <= 100000

Output

As 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 Output

8 0 2

題目大意:

有一堆公羊和母羊,給定K個關系(一定是公羊和母羊的關系),讓你找出從里面任意一頭開始找。找到四頭不同的羊。為你一共有多少種找法。(1 <= n, m, k <= 100000)

解題報告:

? ? ? 給出很多對 雄羊雌羊的朋友關系,讓你數(shù)數(shù),能數(shù)出幾種關系,關系中的四只羊不能有重復的。相當于四只羊中間有三條邊,遍歷中間那條邊即可,最后答案再乘2,因為反過來也是成立的。

AC代碼

#include<cstdio> #include<queue> #include<cstring> #include<cmath> #include<map> #include<iostream> #include<algorithm> #define ll long long using namespace std; const int MAX = 100000 +5; struct Edge {int u,v;Edge(){}Edge(int u,int v):u(u),v(v){} } e[MAX]; ll mile[MAX],femile[MAX]; int top; int main() {int t;int n,m,k,a,b;cin>>t;while(t--) {top = 0;memset(mile,0,sizeof mile);memset(femile,0,sizeof femile);scanf("%d%d%d",&n,&m,&k);for(int i = 1; i<=k; i++) {scanf("%d%d",&a,&b);e[++top] = Edge(a,b);mile[a]++;femile[b]++;}ll ans = 0;for(int i = 1; i<=top; i++) {ans += (mile[e[i].u]-1) * (femile[e[i].v] - 1);}printf("%lld\n",ans*2);}return 0 ; }

?

?

總結

以上是生活随笔為你收集整理的【HDU - 6016】Count the Sheep (思维,类似二分图)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。