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

Problem Description
A new season of Touhou M-1 Grand Prix is approaching. Girls in Gensokyo cannot wait for participating it. Before the registration, they have to decide which combination they are going to compete as. Every girl in Gensokyo is both a boke (funny girl) and a tsukkomi
(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.
 
Input
There are multiple test cases. Process to the End of File.
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.
 
Output
For each test case, output the number of redundant combinations in the first line. Then output the space-separated indexes of the redundant combinations in ascending order in the second line.
 
Sample Input
4 4
1 3
2 3
2 4
3 1
6 6
1 2
3 2
3 4
5 2
5 4
5 6
 
Sample Output
1
2
3
2 4 5
 
Author
Zejun Wu (watashi)
 
Source
 

———————————————————————————————

题意:有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的更多相关文章

  1. HDU-4687 Boke and Tsukkomi 带花树,枚举

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4687 题意:给一个无向图,求所有的最大匹配的情况所不包含的边.. 数据比较小,直接枚举边.先求一次最大 ...

  2. HDU 4687 Boke and Tsukkomi (一般图匹配带花树)

    Boke and Tsukkomi Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

  3. HDOJ 4687 Boke and Tsukkomi 一般图最大匹配带花树+暴力

    一般图最大匹配带花树+暴力: 先算最大匹配 C1 在枚举每一条边,去掉和这条边两个端点有关的边.....再跑Edmonds得到匹配C2 假设C2+2==C1则这条边再某个最大匹配中 Boke and ...

  4. hdu 4687 Boke and Tsukkomi

    Dancing link twice. Find the maximum combination numbers in the first time. Enumerate each node, dan ...

  5. HDU 4687 Boke and Tsukkomi (一般图最大匹配)【带花树】

    <题目链接> 题目大意: 给你n个点和m条边,每条边代表两点具有匹配关系,问你有多少对匹配是冗余的. 解题分析: 所谓不冗余,自然就是这对匹配关系处于最大匹配中,即该匹配关系有意义.那怎样 ...

  6. HDU 4687 Boke and Tsukkomi 一般图匹配,带花树,思路,输出注意空行 难度:4

    http://acm.hdu.edu.cn/showproblem.php?pid=4687 此题求哪些边在任何一般图极大匹配中都无用,对于任意一条边i,设i的两个端点分别为si,ti, 则任意一个极 ...

  7. 2013 Multi-University Training Contest 9

    HDU-4687 Boke and Tsukkomi 题意:给定一个简单图,询问哪些边如果选择的话会使得最大的连边数减少. 解法:套用一般图的最大匹配算法(带花树)先算出最大匹配数,然后枚举一条边被选 ...

  8. [kuangbin带你飞]专题十 匹配问题

        A-L 二分匹配 M-O 二分图多重匹配 P-Q 二分图最大权匹配 R-S 一般图匹配带花树 模板请自己找     ID Origin Title   61 / 72 Problem A HD ...

  9. 二分图水一波~~~~d带你飞

    Current Time: 2016-03-11 17:45:36 Contest Type: Public Start Time: 2016-03-04 13:00:00 Contest Statu ...

随机推荐

  1. Mac Terminal

    一.简介   二.实用 1)update-apps-using-terminal-mac https://www.maketecheasier.com/update-apps-using-termin ...

  2. Spring 属性注入(二)BeanWrapper 结构

    Spring 属性注入(二)BeanWrapper 结构 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) BeanWrap ...

  3. PHP图片处理库Grafika详细教程

    转载自51CTO 开发频道 1.图像基本处理:http://developer.51cto.com/art/201611/520928.htm 2.图像特效处理模块:http://developer. ...

  4. 配置nginx1.8支持thinkPHP3.2 pathinfo模式

    nginx 下conf/nginx.conf 或者自己的vhosts更改以前的参数 location / { root   html; index  index.html index.htm inde ...

  5. applicationContext-common.xml]; nested exception is java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

    14:59:16,747 ERROR ContextLoader:350 - Context initialization failedorg.springframework.beans.factor ...

  6. tomcat运行监控脚本,自动启动

    参见:http://www.cnblogs.com/coffee_cn/p/8279165.html monitor.sh #!/bin/sh monitorlog=/usr/local/tomcat ...

  7. TFS SDK

    vs2013 已包含. 可参考 TFS SDK: Connecting to TFS 2010 & TFS 2012 Programmatically http://geekswithblog ...

  8. Alpha 冲刺 (1/10)

    队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作,对多个目标检测及文字识别模型进行评估.实验,选取较 ...

  9. Django框架之Ajax和form组件

    一.Django框架之查漏补缺 1)models,字段概况 name = models.CharField(max_length=) age = models.IntegerField() price ...

  10. 2018.11.02 洛谷P3952 时间复杂度(模拟)

    传送门 惊叹考场dubuffdubuffdubuff. 这题还没有梭哈难啊233. 直接按照题意模拟就行了. 代码: #include<bits/stdc++.h> using names ...