题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4687

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 ≤ B i ≤ N and the index of the tsukkomi girl 1 ≤ T i ≤ N, where B i != T i.

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

‎新赛季的图豪M-1大奖赛即将到来。根索基约的女孩不能等待参加它。在注册之前,他们必须决定他们将作为哪个组合竞争。根索约的每个女孩都是一个博克(滑稽的女孩)和一个tsukkomi(直的女孩)。每个候选人组合由两个女孩组成,一个博克和一个tsukkomi。女孩可能属于零个或多个候选组合,但一个只能注册为一个正式组合的成员。东道主图豪M-1大奖赛希望尽可能多的正式组合可以参加今年。在这些约束下,某些候选组合实际上是多余的,因为只要必须最大化正式组合的数量,就不可能将其注册为正式组合。因此,他们希望找出这些冗余组合,并停止考虑它们。‎

‎输入‎

‎有多个测试用例。进程到文件结尾。‎
‎每个测试用例的第一行包含两个整数:1 = N = 40,1 = M = ‎‎123,‎‎其中 N 是 Gensokyo 中的女孩数,M 是候选组合的数量。以下 M 行是 M 候选组合,每行各一行。每个组合由两个整数表示,博克女孩 1 = B ‎‎i‎‎ = N 的索引和 tsukkomi 女孩 1 的索引 1 = T ‎‎i‎‎ = N,其中 B ‎‎i‎‎ != T ‎‎i‎‎。‎

‎输出‎

‎对于每个测试用例,输出第一行中的冗余组合数。然后在第二行中按升序输出冗余组合的空间分隔索引。‎

其实这个题本来以为很简单的,最后发现原来自己理解题意理解错了!,看的网上的题解,用到一般图匹配的带花树算法,这个算法自己勉强能理解,可是真的敲不出来,等以后厉害了回来再补,只是会用简单的板子,这里给出借鉴的网上大佬的代码.

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=50;
deque<int> Q;
//g[i][j]存放关系图:i,j是否有边,match[i]存放i所匹配的点
bool g[MAXN][MAXN],inque[MAXN],inblossom[MAXN],vis[150];
int match[MAXN],pre[MAXN],base[MAXN];
int n,m,mmg;
vector<int>res;
struct node
{int u,v;
}com[150];
//找公共祖先
int findancestor(int u,int v){bool inpath[MAXN]={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=findancestor(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 MMG()
{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()
{int a,b;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;com[i].u=a;com[i].v=b;}mmg=MMG();res.clear();for(int i=1;i<=m;i++){a=com[i].u;b=com[i].v;memset(g,false,sizeof(g));for(int j=1;j<=m;j++)if(j!=i){int x=com[j].u,y=com[j].v;if(x==a||x==b||y==a||y==b) continue;g[x][y]=g[y][x]=true;}int t=MMG();if(t!=mmg-1) res.push_back(i);}printf("%d\n",res.size());if(res.size())printf("%d",res[0]);for(int i=1;i<res.size();i++)printf(" %d",res[i]);printf("\n");}return 0;
}
‎

Boke and Tsukkomi——一般图匹配+带花树算法相关推荐

  1. 【学习小记】一般图最大匹配——带花树算法

    Text 一般图的最大匹配仍然是基于寻找增广路的 增广路的定义是这样的一条路径,它不经过重复的点,并且路径两端均没有匹配,且整条路径是非匹配边-匹配边-非匹配边这样交错的. 类比二分图最大匹配的增广路 ...

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

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

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

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

  4. URAL - 1099 Work Scheduling(一般图最大匹配-带花树模板)

    题目链接:点击查看 题目大意:给出n个警卫,接下来给出数个关系,表示两个警卫可以互相配合,现在规定只有可以互相配合的警卫才能留下来继续工作,问最多能有多少个警卫留下来工作,输出匹配方案 题目分析:一般 ...

  5. 一般图最大匹配——带花树

    所谓花,就是如下图所示的一个奇环: 本文中粗边代表现在的匹配边,细边代表该点的前驱(后文会讲解前驱是什么,现在只需要知道每个点和它的前驱在原图中一定是有边的). 如图所示,一朵包含\(2k+1\)个点 ...

  6. 图论 —— 带花树算法

    [概述] 带花树算法用于解决一般图的最大匹配问题. 对于一个图 G(V,E),他的匹配 M 是二元组 (u,v) 组成的集合,其中 u,v∈V,(u,b)∈E,且 M 中不存在重复的点,当 |M| 最 ...

  7. 2020牛客多校第1场I-1 or 2一般图最大匹配带花树

    链接:https://ac.nowcoder.com/acm/contest/5666/I Bobo has a graph with n vertices and m edges where the ...

  8. uoj79 一般图最大匹配 带花树学习(被虐

    辣鸡蒟蒻原来的blog: http://www.elijahqi.win/2018/01/28/uoj79/ 学习资料其一:http://www.csie.ntnu.edu.tw/~u91029/Ma ...

  9. 二分匹配和一般图匹配

    目录 二分匹配 匈牙利算法 练习 1 2 最小覆盖 练习 1 2 二分图一般独立集 一般图 一般图的最大独立集. 一般图匹配 带花树 增广路 联系 BFS神力 奇环 偶环 LCA 代码 二分匹配 匈牙 ...

最新文章

  1. 去掉 Idea 中注入 Mapper 警告的方法
  2. Golang 标准库提供的Log(一)
  3. java中replace函数
  4. Spring - Java/J2EE Application Framework 应用框架 第 17 章 使用Spring邮件抽象层发送Email
  5. virtual DOM和真实DOM的区别_让虚拟DOM和DOMdiff不再成为你的绊脚石
  6. wxWidgets:使用 wxWidgets 资源文件XRC
  7. java js 正则表达式_如何在JavaScript与Java中使用正则表达式
  8. atitit.激活一个窗口总结 swing java .net php
  9. 2021 年百度之星·程序设计大赛 - 初赛二 1002 随机题意(区间贪心)
  10. Failed to connect to d.line-scdn.net port 443: Operation timed out
  11. 网上一好人收集的PDF制作软件大全
  12. GmSSL快速上手指南
  13. 去掉串口硬盘的安全删除硬件图标
  14. hEi2ANzja!;¥WgxjckTxiGZ¥ mp4_限时特价 | ¥499起享深圳东部华侨城两日双人游,住吃玩都有了!...
  15. Python个人常见语法问题
  16. Win10系统wifi图标消失无法联网怎么办
  17. 计算机组成原理实验所用的指令,计算机组成原理实验报告-控制器及微指令系统的操作与运用...
  18. LeetCode第9题 回文数(Palindrome Number)
  19. DML语句(delete,insert,update)
  20. 小说《小城恋情》第三十三章

热门文章

  1. 复现开源论文代码总结
  2. FPN论文解读 和 代码详解
  3. 微信小程序canvas绘制曲线图表
  4. 欢能和南卡电容笔哪款好用?国内主动式电容笔对比
  5. 互联网公司面试——字节跳动算法
  6. 算法实验二 【踩气球】(回溯算法)
  7. [求助贴]python图片全屏截取+定位坐标+图片识别
  8. js 数组求和多种方法
  9. 功率放大器的参数和应用场景是什么
  10. Unity子线程与主线程交互(委托方式)