编程介的小学生 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条)

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的