hdu Marriage Match II 完全不同的最大匹配方案的个数
2012-04-30 09:22
337 查看
Marriage Match II
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)Total Submission(s) : 6 Accepted Submission(s) : 5
[align=left]Problem Description[/align]
Presumably, you all have known the question of stable marriage match. A girl will choose a boy; it is similar as the game of playing house we used to play when we are kids. What a happy time as so many friends playing together. And it is normal that a fight or a quarrel breaks out, but we will still play together after that, because we are kids.
Now, there are 2n kids, n boys numbered from 1 to n, and n girls numbered from 1 to n. you know, ladies first. So, every girl can choose a boy first, with whom she has not quarreled, to make up a family. Besides, the girl X can also choose boy Z to be her boyfriend when her friend, girl Y has not quarreled with him. Furthermore, the friendship is mutual, which means a and c are friends provided that a and b are friends and b and c are friend.
Once every girl finds their boyfriends they will start a new round of this game—marriage match. At the end of each round, every girl will start to find a new boyfriend, who she has not chosen before. So the game goes on and on.
Now, here is the question for you, how many rounds can these 2n kids totally play this game?
[align=left]Input[/align]
There are several test cases. First is a integer T, means the number of test cases.
Each test case starts with three integer n, m and f in a line (3<=n<=100,0<m<n*n,0<=f<n). n means there are 2*n children, n girls(number from 1 to n) and n boys(number from 1 to n).
Then m lines follow. Each line contains two numbers a and b, means girl a and boy b had never quarreled with each other.
Then f lines follow. Each line contains two numbers c and d, means girl c and girl d are good friends.
[align=left]Output[/align]
For each case, output a number in one line. The maximal number of Marriage Match the children can play.
[align=left]Sample Input[/align]
1
4 5 2
1 1
2 3
3 2
4 2
4 4
1 4
2 3
题目意思就是求有多少完全不同的最大匹配方案,开始还理解错了,以为是只要有一个不同的就算一次新的方案呢,现在要求完全不同的匹配方案,只需要求一次HK之后,将所有的匹配边删除掉再做HK就好了,直到某一次最大匹配比前一次小了就停止。在这之前由朋友的朋友是朋友,所以建图的时候注意,可以用并查集维护一下朋友关系。
相关文章推荐
- HDU--3081--Marriage Match II--最大匹配,匈牙利算法
- HDU--3081--Marriage Match II--最大匹配,匈牙利算法
- HDU - 3081 Marriage Match II(二分图最大匹配 + 并查集)
- HDU 3081 Marriage Match II【并查集+二分图最大匹配】
- HDU - 3081 Marriage Match II(最大流+并查集+二分查找)
- HDU 3081 Marriage Match II(最大流 + 并查集)
- hdu 3081 Marriage Match II【并查集+二分匹配---匈牙利】
- hdu 3081 Marriage Match II(二分最大流+并查集+判断满流)
- hdu 3081 Marriage Match II (二分+最大流+并查集)
- HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)
- HDU 3081 Marriage Match II(二分+最大流)
- HDU 3729 I'm Telling the Truth -- 二分图最大匹配 输出方案
- HDU 3081 Marriage Match II —并查集,最大流
- HDU 2236 矩阵不同行列寻找 最小最大数的差值 最小 二分匹配+二分枚举区间
- HDU3081 Marriage Match II 【最大匹配】
- HDU 3081 Marriage Match II (最大流+二分+并查集)
- HDU-3081-Marriage Match II(最大流+并查集+二分)
- N - Marriage Match II - HDU 3081(最大流)
- hdu 2813 二分图最大权匹配 非完全匹配
- HDU 3081 Marriage Match II [二分最大流]+并查集?807★