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 ...
随机推荐
- opencv 学习总结 方法总结
师者传道受业解惑也,图片识别是门学科,需要师者传教,才会较快解开谜团,解开困惑,没人引导,要学会图片识别,有点难度,因为其中的做法超出自己的想象范围. 大家都知道,在超出想象范围,或者从未想到的方式, ...
- hdu 2444(二分图) The Accomodation of Students
http://acm.hdu.edu.cn/showproblem.php?pid=2444 大意是给定n个学生,他们之间可能互相认识,首先判断能不能将这些学生分为两组,使组内学生不认识: 现想将学生 ...
- hdu 5491(2015合肥网赛)The Next
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5491 题意就是,T组测试数据.然后L,S1,S2.L的二进制中有x个1,x满足 S1<=x< ...
- 错误:在非结构或联合中请求成员‘next’
#include <stdio.h> #include <stdlib.h> #define ElemType int #define Status int #define O ...
- BZOJ4326或洛谷2680 运输计划
BZOJ原题链接 洛谷原题链接 用\(LCA\)初始化出所有运输计划的原始时间,因为答案有单调性,所以二分答案,然后考虑检验答案. 很容易想到将所有超出当前二分的答案的运输计划所经过的路径标记,在这些 ...
- Python-多进程VS多线程
多进程VS多线程 功能: 进程:能够完成多任务,比如,同时运行多个QQ 线程:能够完成多任务,比如一个QQ中的多个聊天窗口 定义 进程:系统进行资源分配和测试的一个独立单位,线程自己基本上不拥有系统资 ...
- python 读取xml
#!/usr/bin/python # -*- coding: UTF- -*- from xml.dom.minidom import parse import xml.dom.minidom # ...
- oracle创建、删除 数据库、建立表空间以及插入 删除 修改表
一.创建.删除数据库 oracle OraDb11g_home->配置和移植工具->Database configration Assistant->...然后可以创建或者删除数据 ...
- 2018.11.09 bzoj2165: 大楼(倍增+floyd)
传送门 先倍增出iii使得2i2^i2i时间时刚好有每个点能够到mmm层及以上. 然后就可以用floyd+floyd+floyd+倍增求出刚好不超过mmm层的时间,最后再补一层就行了. 代码: #pr ...
- java常用设计模式六:适配器模式
一.定义 适配器模式把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作.比如以下的场景: 用手机充电为例,有一个手机的插孔是TypeC口,现在只 ...