编程介的小学生 2017-01-09 12:43 采纳率: 20.5%
浏览 861
已采纳

Marriage Match

问题描述 :

You may know the funny problem “The Stable Marriage Problem”. Now let’s find a new match algorithm.
Firstly the women and men stand in a line separately and each woman will choose the man she likes.
Then it’s your task to make a match for these people. You should choose m women and m men from the initial queues. Let them stand in a line separately by initial order. If the woman stands in the ith place do not like the man stands in the ith place, the match is unacceptable. To increase the possibility of the match, the women can accept the men their friends like. Please find out the maximal m.
输入:

There are several test cases.
Each test case starts with two integer p and q in a line means the number of women and the number of men.(0 < p , q <= 100000)
Then a line with p numbers follows means the queue of women. (The id ranges from 1 to p)
Then a line with q numbers follows means the queue of men. (The id ranges from 1 to q)
Then a line with p numbers which means the man the ith woman likes.
Then a line with an integer t, means the number of friendships between women.(0 < t < 100000)
Then t lines follow. Each line contains two numbers a and b means a and b are friends.(a!=b, 1 <= a, b <= p)
You may support the friendship can transmit. If a and b are friends and c and b are friends, then a and c are friends. Notice every woman will have no more than five friends.
输出:

There are several test cases.
Each test case starts with two integer p and q in a line means the number of women and the number of men.(0 < p , q <= 100000)
Then a line with p numbers follows means the queue of women. (The id ranges from 1 to p)
Then a line with q numbers follows means the queue of men. (The id ranges from 1 to q)
Then a line with p numbers which means the man the ith woman likes.
Then a line with an integer t, means the number of friendships between women.(0 < t < 100000)
Then t lines follow. Each line contains two numbers a and b means a and b are friends.(a!=b, 1 <= a, b <= p)
You may support the friendship can transmit. If a and b are friends and c and b are friends, then a and c are friends. Notice every woman will have no more than five friends.
样例输入:

4 4
1 3 2 4
1 4 2 3
2 3 1 2
2
1 2
3 4
样例输出:

2

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-01-15 15:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容