Hdu4687 Boke and Tsukkomi
Boke and Tsukkomi
Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 1215 Accepted Submission(s): 386
(straight girl). Every candidate combination is made up of two girls, a boke and a tsukkomi. A girl may belong to zero or more candidate combinations, but one can only register as a member of one formal combination. The host of Touhou M-1 Grand Prix hopes
that as many formal combinations as possible can participate in this year. Under these constraints, some candidate combinations are actually redundant as it\'s impossible to register it as a formal one as long as the number of formal combinations has to be
maximized. So they want to figure out these redundant combinations and stop considering about them.

The first line of each test case contains two integers: 1 ≤ N ≤ 40 and 1 ≤ M ≤ 123, where N is the number of girls in Gensokyo, and M is the number of candidate combinations. The following M lines are M candidate combinations, one by each line.
Each combination is represented by two integers, the index of the boke girl 1 ≤ Bi ≤ N and the index of the tsukkomi girl 1 ≤ Ti ≤ N, where Bi != Ti.
1 3
2 3
2 4
3 1
6 6
1 2
3 2
3 4
5 2
5 4
5 6
2
3
2 4 5
———————————————————————————————
题意:有n个女孩,她们之间有k对可能的组合,但参赛时每个人只能参加一个组合,在组合数量最大化时有些组合是多余的,但使组合数量最大化可能有多种方式,找出这些多余的组合
解题思路:一般图匹配带花树,这题不能这样判断,当一个组合不选择时,组合数量仍能达到最大化,它就是多余组合,因为可能选了这个组合也能使组合数量达到最大化。应该固定一个组合,若其他组合形成的组合数量等于之前组合数量减一,那么它就不是多余的,否则它就是多余的。也就是说要让剩余的组合无论怎么选都能达到组合数量最大化
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f; const int MAXN = 250;
int N; //点的个数,点的编号从1到N
bool Graph[MAXN][MAXN];
int Match[MAXN];
bool InQueue[MAXN],InPath[MAXN],InBlossom[MAXN];
int Head,Tail;
int Queue[MAXN];
int Start,Finish;
int NewBase;
int Father[MAXN],Base[MAXN];
int a[MAXN],b[MAXN],ans[MAXN]; void Push(int u)
{
Queue[Tail] = u;
Tail++;
InQueue[u] = true;
}
int Pop()
{
int res = Queue[Head];
Head++;
return res;
}
int FindCommonAncestor(int u,int v)
{
memset(InPath,false,sizeof(InPath));
while(true)
{
u = Base[u];
InPath[u] = true;
if(u == Start) break;
u = Father[Match[u]];
}
while(true)
{
v = Base[v];
if(InPath[v])break;
v = Father[Match[v]];
}
return v;
}
void ResetTrace(int u)
{
int v;
while(Base[u] != NewBase)
{
v = Match[u];
InBlossom[Base[u]] = InBlossom[Base[v]] = true;
u = Father[v];
if(Base[u] != NewBase) Father[u] = v;
}
}
void BloosomContract(int u,int v)
{
NewBase = FindCommonAncestor(u,v);
memset(InBlossom,false,sizeof(InBlossom));
ResetTrace(u);
ResetTrace(v);
if(Base[u] != NewBase) Father[u] = v;
if(Base[v] != NewBase) Father[v] = u;
for(int tu = 1; tu <= N; tu++)
if(InBlossom[Base[tu]])
{
Base[tu] = NewBase;
if(!InQueue[tu]) Push(tu);
}
}
void FindAugmentingPath()
{
memset(InQueue,false,sizeof(InQueue));
memset(Father,0,sizeof(Father));
for(int i = 1; i <= N; i++)
Base[i] = i;
Head = Tail = 1;
Push(Start);
Finish = 0;
while(Head < Tail)
{
int u = Pop();
for(int v = 1; v <= N; v++)
if(Graph[u][v] && (Base[u] != Base[v]) && (Match[u] != v))
{
if((v == Start) || ((Match[v] > 0) && Father[Match[v]] > 0))
BloosomContract(u,v);
else if(Father[v] == 0)
{
Father[v] = u;
if(Match[v] > 0)
Push(Match[v]);
else
{
Finish = v;
return;
}
}
}
}
}
void AugmentPath()
{
int u,v,w;
u = Finish;
while(u > 0)
{
v = Father[u];
w = Match[v];
Match[v] = u;
Match[u] = v;
u = w;
}
}
void Edmonds()
{
memset(Match,0,sizeof(Match));
for(int u = 1; u <= N; u++)
if(Match[u] == 0)
{
Start = u;
FindAugmentingPath();
if(Finish > 0)AugmentPath();
}
} int main()
{ int u,v,m;
while(~scanf("%d%d",&N,&m))
{
memset(Graph,false,sizeof(Graph)); for(int i=1; i<=m; i++)
{
scanf("%d%d",&a[i],&b[i]);
Graph[a[i]][b[i]] = Graph[b[i]][a[i]] = true;
}
Edmonds();
int tot=0;
for(int i=1; i<=N; i++)
if(Match[i]>0)
tot++;
int cnt=0;
for(int i=1; i<=m; i++)
{
int aa=a[i],bb=b[i];
memset(Graph,false,sizeof(Graph)); for(int i=1; i<=m; i++)
{
if(a[i]==aa||b[i]==aa||a[i]==bb||b[i]==bb)
continue;
Graph[a[i]][b[i]] = Graph[b[i]][a[i]] = true;
} Edmonds();//进行匹配 int tt=0;
for(int i=1; i<=N; i++)
if(Match[i]>0)
tt++;
if(tt!=tot-2)
ans[cnt++]=i; } printf("%d\n",cnt);
int q=0;
for(int i=0; i<cnt; i++)
{
if(q++)
printf(" ");
printf("%d",ans[i]);
}
printf("\n");
} return 0;
}
Hdu4687 Boke and Tsukkomi的更多相关文章
- HDU-4687 Boke and Tsukkomi 带花树,枚举
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4687 题意:给一个无向图,求所有的最大匹配的情况所不包含的边.. 数据比较小,直接枚举边.先求一次最大 ...
- HDU 4687 Boke and Tsukkomi (一般图匹配带花树)
Boke and Tsukkomi Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Othe ...
- HDOJ 4687 Boke and Tsukkomi 一般图最大匹配带花树+暴力
一般图最大匹配带花树+暴力: 先算最大匹配 C1 在枚举每一条边,去掉和这条边两个端点有关的边.....再跑Edmonds得到匹配C2 假设C2+2==C1则这条边再某个最大匹配中 Boke and ...
- hdu 4687 Boke and Tsukkomi
Dancing link twice. Find the maximum combination numbers in the first time. Enumerate each node, dan ...
- HDU 4687 Boke and Tsukkomi (一般图最大匹配)【带花树】
<题目链接> 题目大意: 给你n个点和m条边,每条边代表两点具有匹配关系,问你有多少对匹配是冗余的. 解题分析: 所谓不冗余,自然就是这对匹配关系处于最大匹配中,即该匹配关系有意义.那怎样 ...
- HDU 4687 Boke and Tsukkomi 一般图匹配,带花树,思路,输出注意空行 难度:4
http://acm.hdu.edu.cn/showproblem.php?pid=4687 此题求哪些边在任何一般图极大匹配中都无用,对于任意一条边i,设i的两个端点分别为si,ti, 则任意一个极 ...
- 2013 Multi-University Training Contest 9
HDU-4687 Boke and Tsukkomi 题意:给定一个简单图,询问哪些边如果选择的话会使得最大的连边数减少. 解法:套用一般图的最大匹配算法(带花树)先算出最大匹配数,然后枚举一条边被选 ...
- [kuangbin带你飞]专题十 匹配问题
A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找 ID Origin Title 61 / 72 Problem A HD ...
- 二分图水一波~~~~d带你飞
Current Time: 2016-03-11 17:45:36 Contest Type: Public Start Time: 2016-03-04 13:00:00 Contest Statu ...
随机推荐
- PyQt5速成教程
博客地址 https://www.jianshu.com/nb/26159952
- c# 上传excel数据总结(一)线程的使用
1: 因为程序涉及到上传,开始暂停,继续,删除, thread 在老版本用使用th.Abort(); th.Resume(); 停止 恢复 th.Suspend(); 挂起 猛的一看挺合适啊..但微 ...
- delphi新手到高手的工具--castalia
castalia翻译是 神泉 ,是delphi的一个优秀第三方工具.其重构功能尤为突出.代码实时编译提示也很棒. 自卑delphi开发工具没有eclipse那么强大的提示?有castalia为你提升信 ...
- linux shell 重定向中的 & 符号
写一个简单的 demo 示例 #include <stdio.h> int main() { fprintf(stdout, "stdout output\n"); f ...
- tp5安装验证码
- 20165213 java学习第一周
20165213 -2018-2<Java程序设计>第一周学习总结 教材学习内容总结 java的四个特点:面向对象.平台无关性.动态性.简单. java编写程序步骤:再有jdk的情况下,先 ...
- Two Sum LT1
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- luaFramework
BeginStaticLibs 参考CustomSettings.cs public static List<Type> staticClassTypes = new List<T ...
- Notepad++语言格式设置,自定义扩展名关联文件格式
简单粗暴--直接上图
- python - package - bs4 - 美味汤
Beautiful Soup 3 only works on Python 2.x, but Beautiful Soup 4 also works on Python 3.x. 你可能在寻找 Bea ...