Are you interested in pets? There is a very famous pets shop in the center of the ACM city. There are totally m pets in the shop, numbered from 1 to m. One day, there are n customers in the shop, which are numbered from 1 to n. In order to sell pets to as more customers as possible, each customer is just allowed to buy at most one pet. Now, your task is to help the manager to sell as more pets as possible. Every customer would not buy the pets he/she is not interested in it, and every customer would like to buy one pet that he/she is interested in if possible.

Input

There is a single integer T in the first line of the test data indicating that there are T(T≤100) test cases. In the first line of each test case, there are three numbers n, m(0≤n,m≤100) and e(0≤e≤n*m). Here, n and m represent the number of customers and the number of pets respectively.

In the following e lines of each test case, there are two integers x(1≤x≤n), y(1≤y≤m) indicating that customer x is not interested in pet y, such that x would not buy y.

Output

For each test case, print a line containing the test case number (beginning with 1) and the maximum number of pets that can be sold out.

Sample Input

1
2 2 2
1 2
2 1

Sample Output

Case 1: 2
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<cmath> const int maxn=1e5+;
typedef long long ll;
using namespace std; int n,m,k;
int link[];
bool visit[],map[][];
bool dfs(int a)
{
for(int i=;i<=m;i++)
if(map[a][i]== && !visit[i])
{
visit[i]=;
if(link[i]== || dfs(link[i]))
{
link[i]=a;
return true;
}
}
return false;
}
int main()
{
int a,b,ans;
int T;
cin>>T;
int cnt=;
while(T--)
{
// memset(visit,0,sizeof(visit));
memset(link,,sizeof(link));
memset(map,,sizeof(map));
cin>>n>>m>>k;
ans=;
for(int i=;i<=k;i++)
{
scanf("%d%d",&a,&b);
map[a][b]=;
}
for(int i=;i<=n;i++)
{
memset(visit,,sizeof(visit));
if(dfs(i))
ans++;
}
printf("Case %d: %d\n",cnt++,ans);
}
}

最新文章

  1. 自定义UICollectionLayout布局 —— UIKit之学习UICollectionView记录一《瀑布流》
  2. 【Android测试】Android截图的深水区
  3. MongoDB学习笔记(索引)
  4. 学习zepto.js(Hello World)
  5. Remove Invalid Parentheses
  6. loopback 04
  7. Asp.net的post提交方式
  8. spark结合 Openfire服务器,发送聊天消息
  9. NGINX+UWSGI部署生产的DJANGO代码
  10. hdu5358 First One(尺取法)
  11. DBCP连接池的使用
  12. JavaScript高级程序设计:第一章
  13. [Python Study Notes]实现对鼠标控制
  14. EntityFramework Code-First—领域类配置之DataAnnotations
  15. 10 Tensorflow模型保存与读取
  16. Django项目在linux系统中虚拟环境部署
  17. 对numpy中shape的理解
  18. Kubernetes部署SpringCloud(三) 使用 Ingress-nginx 暴露服务
  19. W phase 学习
  20. 本地连接服务器的mongodb

热门文章

  1. python2.3嵌套if结构:
  2. JSP中contentType、pageEncoding和meta charset的区别
  3. 经典的IPC问题
  4. Python创建进程、线程的两种方式
  5. C#LeetCode刷题之#345-反转字符串中的元音字母​​​​​​​(Reverse Vowels of a String)
  6. Window C盘 占满原因之一
  7. idea的热加载与热部署
  8. 设计模式:桥接模式及代码示例、桥接模式在jdbc中的体现、注意事项
  9. C语言文件读写命令fprintf和fscanf
  10. MySQL &#183; 性能优化 &#183; MySQL常见SQL错误用法(转自-阿里云云栖社区)