HDU 3277 Marriage Match III

来源:互联网 发布:以色列 知乎 编辑:程序博客网 时间:2024/06/06 02:10

2011-05-16

17:57:47

Marriage Match III

Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 435    Accepted Submission(s): 106

Problem Description
Presumably, you all have known the question of stable marriage match. A girl will choose a boy; it is similar as the ever game of play-house . What a happy time as so many friends play 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. As 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. On the other hand, in order to play more times of marriage match, every girl can accept any K boys. If a girl chooses a boy, the boy must accept her unconditionally whether they had quarreled before or not.

Now, here is the question for you, how many rounds can these 2n kids totally play this game?
 

 

Input
There are several test cases. First is an integer T, means the number of test cases.
Each test case starts with three integer n, m, K and f in a line (3<=n<=250, 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.
 

 

Output
For each case, output a number in one line. The maximal number of Marriage Match the children can play.
 

 

Sample Input
14 5 1 21 12 33 24 24 41 42 3
 

 

Sample Output
3
题意:和3081差不多,就是多了每个女孩可以另外选任意k个不喜欢的;
思路:将每个女孩u分为u1,u2,若u喜欢v则加一条u1到v的边 否则加一条u2到v的边,令加u1到u2的容量为k的边;