题干:

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)

解题报告:

给出很多对 雄羊雌羊的朋友关系,让你数数,能数出几种关系,关系中的四只羊不能有重复的。相当于四只羊中间有三条边,遍历中间那条边即可,最后答案再乘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 (思维,类似二分图)相关推荐

  1. HDU - 6016 Count the Sheep(二分图+思维)

    题目链接:点击查看 题目大意:给出左右两个子集分别,再给出k条边,问能否找出四个点,让其连成一条路径 题目分析:一开始看到这个题肯定是个二分图,又因为有边,我就往度数上面想,一看四个点,就在想能不能枚 ...

  2. hdu 6016 Count the Sheep

    BestCoder Round #92 B题 (今天突然想起来这道题在做的时候卡了cin 而且似乎也有爆int的坑 就拿出来记录一下 ((这道题能用来测试输入输出外挂的性能 中文题意不解释 比赛的时候 ...

  3. HDU 3729 I'm Telling the Truth(二分图最大匹配)

    HDU 3729 I'm Telling the Truth(二分图最大匹配) http://acm.hdu.edu.cn/showproblem.php?pid=3729 题意: 一位老师想问N位同 ...

  4. HDU 2389 Rain on your Parade (二分图匹配)

    题意:天马上就要下雨了,然后有n个人,m把伞,然后分别给出人的坐标和他们跑的速度,以及伞的坐标,然后问在t时间内,最多能有多少人拿到伞. 题解:二分图匹配 之前做过一道类似的题目,是用最大流做的,但这 ...

  5. HDU 6092 Rikka with Subset 思维 递推

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=6092 题目描述: 给你一个集合的所有子集各个和, 让你找到这个集合, 输出字典序最小 解题思路: 下 ...

  6. HDU 3336 Count the string(KMP+DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3336 题意:给你一个字符串,计算其所有前缀在该字符串出现的次数的总和. 思路:next[j]=i,代表 ...

  7. HDU 3336 Count the string KMP

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...

  8. HDU 4588 Count The Carries 数学

    Count The Carries Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  9. HDU - 1151 Air Raid(最小路径覆盖-二分图最大匹配)

    题目链接:点击查看 题目大意:给出一个有向图,现在需要在不同的地方空降伞兵,保证所有伞兵沿着道路可以走完所有城市,求出最少伞兵的数量 题目分析:我们的目的是要用最少的路径覆盖所有顶点,换句话说就是二分 ...

最新文章

  1. 线程和进程有什么区别?
  2. 基于redis AE异步网络架构
  3. 【计算机网络】第五章 数据链路层(3)
  4. Django - Python3 常用命令
  5. Socket 套接字
  6. android debug bridge tools_如何优雅的管理多环境下的Android代码
  7. Spark SQL(九)之基于用户的推荐公式
  8. c语言函数调用参数调用的太少,浅谈C语言函数调用参数压栈的相关问题
  9. linux命令cp命令行参数,linux命令之cp命令参数及用法详解
  10. mysql 设置 character_set_server_MySQL:简单记录character_set_server影响参数
  11. php 回收png,关于php:从其他Png中减去Png,保留透明度,ImageMagick
  12. 前端面试题大集合:来自真实大厂的532道面试题(只有题,没有答案)
  13. Bailian4122 切割回文【DP】
  14. 用python画漂亮图-python如何画出漂亮的地图?
  15. 3月3日 单灭点、双灭点、单应矩阵求解相机姿态,世界坐标-相机坐标-图像坐标-像素坐标四个坐标系的变换关系,通过Vanishing Points计算焦距和像心
  16. 苹果cms影视源码的安装和使用
  17. python 目标跟踪算法_目标跟踪入门——目标跟踪算法综述
  18. linux4 系统下载,SysLinux 4.0.4 下载
  19. python json.dumps(output) ^ SyntaxError: invalid syntax
  20. 好性格让孩子受用终生

热门文章

  1. 1668智能下数教程视频_你需要的教程合集更新
  2. 空间留言软件_电脑硬盘空间提示不足,原来还可以这么做,真是学到老活到老...
  3. L1-056 猜数字 (20 分)
  4. spring security:自定义认证成功处理器
  5. stm32 isp下载官方软件android_OpenCanvas免费版下载_OpenCanvas绘图软件官方版下载7.0.25...
  6. Linux下gSOAP的使用 (c++)
  7. 在何时该用什么方式编译WinCE
  8. python访问共享文件夹 exist false_python os.path.exists()对于存在的nfs挂载目录文件失败...
  9. leftjoin多表联合查询_leetcode-sql练习精讲系列文章——一、多表如何连接
  10. 伪指令endp告诉汇编程序_全国2004年10月高等教育自学考试微型计算机原理及应用试题历年试卷...