HDU 4687 Boke and Tsukkomi (一般图匹配带花树)
Boke and Tsukkomi
Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)
Total Submission(s): 336 Accepted Submission(s): 116
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
/* ***********************************************
Author :kuangbin
Created Time :2013/8/23 19:28:08
File Name :F:\2013ACM练习\专题学习\图论\一般图匹配带花树\HDU4687.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int MAXN = ;
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 Count;
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 = ; tu <= N; tu++)
if(InBlossom[Base[tu]])
{
Base[tu] = NewBase;
if(!InQueue[tu]) Push(tu);
}
}
void FindAugmentingPath()
{
memset(InQueue,false,sizeof(InQueue));
memset(Father,,sizeof(Father));
for(int i = ;i <= N;i++)
Base[i] = i;
Head = Tail = ;
Push(Start);
Finish = ;
while(Head < Tail)
{
int u = Pop();
for(int v = ; v <= N; v++)
if(Graph[u][v] && (Base[u] != Base[v]) && (Match[u] != v))
{
if((v == Start) || ((Match[v] > ) && Father[Match[v]] > ))
BloosomContract(u,v);
else if(Father[v] == )
{
Father[v] = u;
if(Match[v] > )
Push(Match[v]);
else
{
Finish = v;
return;
}
}
}
}
}
void AugmentPath()
{
int u,v,w;
u = Finish;
while(u > )
{
v = Father[u];
w = Match[v];
Match[v] = u;
Match[u] = v;
u = w;
}
}
void Edmonds()
{
memset(Match,,sizeof(Match));
for(int u = ; u <= N; u++)
if(Match[u] == )
{
Start = u;
FindAugmentingPath();
if(Finish > )AugmentPath();
}
}
int getMatch()
{
Edmonds();
Count = ;
for(int u = ; u <= N;u++)
if(Match[u] > )
Count++;
return Count/;
} bool g[MAXN][MAXN];
pair<int,int>p[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int m;
while(scanf("%d%d",&N,&m)==)
{
memset(g,false,sizeof(g));
memset(Graph,false,sizeof(Graph));
int u,v;
for(int i = ;i <= m;i++)
{
scanf("%d%d",&u,&v);
p[i] = make_pair(u,v);
g[u][v] = true;
g[v][u] = true;
Graph[u][v] = true;
Graph[v][u] = true;
}
int cnt0 = getMatch();
//cout<<cnt0<<endl;
vector<int>ans;
for(int i = ;i <= m;i++)
{
u = p[i].first;
v = p[i].second;
memcpy(Graph,g,sizeof(g));
for(int j = ;j <= N;j++)
Graph[j][u] = Graph[u][j] = Graph[j][v] = Graph[v][j] = false;
int cnt = getMatch();
//cout<<cnt<<endl;
if(cnt < cnt0-)
ans.push_back(i);
}
int sz = ans.size();
printf("%d\n",sz);
for(int i = ;i < sz;i++)
{
printf("%d",ans[i]);
if(i < sz-)printf(" ");
}
printf("\n");
}
return ;
}
HDU 4687 Boke and Tsukkomi (一般图匹配带花树)的更多相关文章
- HDU 4687 Boke and Tsukkomi 一般图匹配,带花树,思路,输出注意空行 难度:4
http://acm.hdu.edu.cn/showproblem.php?pid=4687 此题求哪些边在任何一般图极大匹配中都无用,对于任意一条边i,设i的两个端点分别为si,ti, 则任意一个极 ...
- HDOJ 4687 Boke and Tsukkomi 一般图最大匹配带花树+暴力
一般图最大匹配带花树+暴力: 先算最大匹配 C1 在枚举每一条边,去掉和这条边两个端点有关的边.....再跑Edmonds得到匹配C2 假设C2+2==C1则这条边再某个最大匹配中 Boke and ...
- HDU 4687 Boke and Tsukkomi (一般图最大匹配)【带花树】
<题目链接> 题目大意: 给你n个点和m条边,每条边代表两点具有匹配关系,问你有多少对匹配是冗余的. 解题分析: 所谓不冗余,自然就是这对匹配关系处于最大匹配中,即该匹配关系有意义.那怎样 ...
- kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树
二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...
- URAL 1099. Work Scheduling (一般图匹配带花树)
1099. Work Scheduling Time limit: 0.5 secondMemory limit: 64 MB There is certain amount of night gua ...
- URAL1099 Work Scheduling —— 一般图匹配带花树
题目链接:https://vjudge.net/problem/URAL-1099 1099. Work Scheduling Time limit: 0.5 secondMemory limit: ...
- URAL1099. Work Scheduling(一般图匹配带花树开花算法)
1099. Work Scheduling Time limit: 0.5 second Memory limit: 64 MB There is certain amount of night gu ...
- hdu 4687 Boke and Tsukkomi
Dancing link twice. Find the maximum combination numbers in the first time. Enumerate each node, dan ...
- ZOJ 3316 Game 一般图最大匹配带花树
一般图最大匹配带花树: 建图后,计算最大匹配数. 假设有一个联通块不是完美匹配,先手就能够走那个没被匹配到的点.后手不论怎么走,都必定走到一个被匹配的点上.先手就能够顺着这个交错路走下去,最后一定是后 ...
随机推荐
- angular项目中使用angular-material2
Step 1: Install Angular Material and Angular CDK npm install --save @angular/material @angular/cdk n ...
- MySQL 操作总结
1. 数据库级别操作 1.1 创建数据库 CREATE DATABASE db1 default charset utf8 collate utf8_general_ci; 1.2 删除数据库 DRO ...
- Q:WCHAR转化为CHAR
A: int len =WideCharToMultiByte(CP_ACP,0,此处是WCHAR的参数,-1,NULL,0,NULL,NULL); WideCharToMultiByte(CP_AC ...
- 删除 list 集合中的元素
删除 list 集合中的元素,当删除的元素有多个的时候,只能使用迭代器来删除. 当删除 list 集合中的元素只有一个的时候,有三种方法都可以实现. import java.util.ArrayLis ...
- 20179202《Linux内核原理与分析》第一周作业
实验一 Linux 系统简介 这一节主要学习了Linux的历史,重要人物以及学习Linux的方法.Linux和Windows在是否收费.软件与支持.安全性.可定制性和应用范畴等方面都存在着区别.目前感 ...
- PAT L2-018. 多项式A除以B
暴力,模拟. 比赛搞了一个小时搞到了$1$分.赛场上不够冷静......之前没接触过多项式除法,但赛场上想到了除法的规则,莫名其妙写的时候不知道哪里崩了.对于这样的题目,应该先测一测数据的指数是不是很 ...
- disconf-client-for-java
一.disconf客户端部署 disconf目前仅支持java客户端,下文针对java客户端安装作为整理,记录下安装部署的步骤 1.环境依赖 首先需要安装java环境及maven环境,不再过多介绍 2 ...
- vue实现对数据的增删改查(CURD)
vue实现对数据的增删改查(CURD) 导语: 网上看到一个写的比较好的学习文章,转载分享一下 在管理员的一些后台页面里,个人中心里的数据列表里,都会有对这些数据进行增删改查的操作.比如在管理员后台的 ...
- struts2的action编写
例 HelloWorld.jsp <% @ page contentType = "text/html; charset=UTF-8 " %> <% @ tagl ...
- Web应用程序信息收集工具wig
Web应用程序信息收集工具wig 很多网站都使用成熟的Web应用程序构建,如CMS.分析网站所使用的Web应用程序,可以快速发现网站可能存在的漏洞.Kali Linux新增加了一款Web应用程序信 ...