HDUOJ 4687 Boke and Tsukkomi

题目链接

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

一般图最大匹配~
题目要求多余的边,考虑割边即可,先求出原图的最大匹配数 numnumnum,若割边后求处的最大匹配数不满足 cnt!=num−1cnt!=num-1cnt!=num−1,则说明这条边是多余的,AC代码如下:

#include <bits/stdc++.h>
using namespace std;
const int N=150;
deque<int>q;
vector<int>ans;
bool g[N][N],inque[N],inblossom[N],vis[N];
int match[N],pre[N],base[N];
int n,m,a,b;struct node{int u,v;
}e[N];
int Find(int u,int v){bool inpath[N]={false};while(1){u=base[u];inpath[u]=true;if(match[u]==-1)break;u=pre[match[u]];}while(1){v=base[v];if(inpath[v])return v;v=pre[match[v]];}
}void reset(int u,int anc){while(u!=anc){int v=match[u];inblossom[base[u]]=1;inblossom[base[v]]=1;v=pre[v];if(base[v]!=anc)pre[v]=match[u];u=v;}
}void contract(int u,int v,int n){int anc=Find(u,v);memset(inblossom,0,sizeof(inblossom));reset(u,anc);reset(v,anc);if(base[u]!=anc)pre[u]=v;if(base[v]!=anc)pre[v]=u;for(int i=1;i<=n;i++)if(inblossom[base[i]]){base[i]=anc;if(!inque[i]){q.push_back(i);inque[i]=1;}}
}bool dfs(int s,int n){for(int i=0;i<=n;i++)pre[i]=-1,inque[i]=0,base[i]=i;q.clear();q.push_back(s);inque[s]=1;while(!q.empty()){int u=q.front();q.pop_front();for(int v=1;v<=n;v++){if(g[u][v]&&base[v]!=base[u]&&match[u]!=v){if(v==s||(match[v]!=-1&&pre[match[v]]!=-1))contract(u,v,n);else if(pre[v]==-1){pre[v]=u;if(match[v]!=-1)q.push_back(match[v]),inque[match[v]]=1;else{u=v;while(u!=-1){v=pre[u];int w=match[v];match[u]=v;match[v]=u;u=w;}return true;}}}}}return false;
}int calculate()
{int ans=0;memset(match,-1,sizeof(match));for(int i=1;i<=n;i++)if(match[i]==-1&&dfs(i,n)) ans++;return ans;
}int main()
{while(~scanf("%d%d",&n,&m)){memset(g,false,sizeof(g));for(int i=1;i<=m;i++){scanf("%d%d",&a,&b);g[a][b]=g[b][a]=true;e[i].u=a;e[i].v=b;}ans.clear();int res=calculate();for(int i=1;i<=m;i++){a=e[i].u,b=e[i].v;memset(g,false,sizeof(g));for(int j=1;j<=m;j++){if(i!=j){int x=e[j].u,y=e[j].v;if(x==a||x==b||y==a||y==b) continue;g[x][y]=g[y][x]=true;}}int t=calculate();if(t!=res-1) ans.push_back(i);}printf("%d\n",ans.size());for(int i=0;i<ans.size();i++)i==0?printf("%d",ans[i]):printf(" %d",ans[i]);puts("");}return 0;
}

HDUOJ 4687 Boke and Tsukkomi相关推荐

  1. HDU - 4687 Boke and Tsukkomi(一般图最大匹配-带花图)

    题目链接:点击查看 题目大意:给出n个人和m对匹配,现在问有多少组匹配是不必要的,按照升序输出答案 题目分析:因为题目给的N比较小,所以一开始我的想法是先计算出最大匹配,而后枚举每一条边被删除,然后计 ...

  2. HDU 4687 Boke and Tsukkomi【带花树】

    题目链接 题意:一般图最大匹配后会有冗余的小组,求出这些冗余的小组. 明白题意后思路其实非常简单,先求一遍一般图最大匹配,然后枚举每个小组,如果这个小组冗余的话,去掉这个小组之后剩下的小组应该少于原来 ...

  3. Boke and Tsukkomi——一般图匹配+带花树算法

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4687 A new season of Touhou M-1 Grand Prix is approach ...

  4. Boke and Tsukkomi (一般图匹配+暴力)

    https://blog.csdn.net/weyuli/article/details/10141881 根据这篇博客作为模板

  5. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  6. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

  7. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

  8. 老鱼的-kuangbin专题题解

    kuangbin专题问题一览 专题一 简单搜索 POJ 1321 棋盘问题 POJ 2251 Dungeon Master POJ 3278 Catch That Cow POJ 3279 Flipt ...

  9. java合并单元格边框不完整,java poi 合并单元格后边框问题

    2016 CCPC 东北地区重现赛 1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08   HDU5929 Basic Data Structure    模拟 ...

最新文章

  1. 中汽创智科技首席人工智能官丁华杰:AI赋能自动驾驶的几点思考
  2. python如何打开一个大文件?
  3. NATS服务器部署及测试
  4. mysql like反义_MySQL条件检索_WHERE
  5. java 什么是内部类_讨论Java中的内部类是什么?
  6. 【JQuery NoviceToNinja系列】目录
  7. 基于PyQT5的图书管理系统(含文档,源码,安装部署简单)
  8. cad查看_CAD手机看图软件中批注的图片在电脑上如何查看?
  9. mysql 1194_打开网页提示mysql发生错误,错误号1194,请问下该怎么解决? 爱问知识人...
  10. 基因家族分析⑤:进化树构建
  11. USB billboard
  12. 解决安卓手机H5页面input获得焦点时页面挤压或者底部上移
  13. 嵩天老师python123测验7: 文件和数据格式化 (第7周)
  14. maple java,讲解:MACM 401、Maple worksheet、Java,Python、Java,c++SQL|
  15. pyplot中文手册_matplotlib手册(1)-pyplot使用
  16. 6-18位包含数字字母,大小写,特殊字符,正则表达式
  17. 夜神模拟器链接不上ADB问题
  18. 2023华为OD面试手撕代码经验分享
  19. 编程人生(1) 我的软件
  20. Abbkine细胞周期染色试剂盒特色和实验建议

热门文章

  1. 自媒体账号数据分析从何入手?
  2. PicGo+gitee搭建个人图床
  3. php7实现http和https请求web服务-通用工具类
  4. 深度学习三大框架对比
  5. 2022年驾驶员考试驾驶员技师考试模拟试题卷及答案
  6. c语言抽象数据类型复数,抽象数据类型复数的实现..doc
  7. Python该怎么入门?Python入门教程(非常详细)
  8. Vue 子组件向父组件传值失效
  9. Tita OKR分享:如何进行OKR评分?
  10. 渗透测试学习笔记(一)注入篇-盲注 二次注入 宽字节注入