hdu 4751 2013南京赛区网络赛 二分图判断 **
和以前做过的一个二分图颇为相似,以前的是互相不认识的放在一组,这个是互相认识的,本质上是相同的
是 hdu 2444
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
#define MAXN 202
vector<int>EV[MAXN];
int linker[MAXN];
bool used[MAXN];
int uN;
int matchs[MAXN],cnt[MAXN];
bool dfs(int u)
{
int i;
for(i=;i<EV[u].size();i++)
{
int v=EV[u][i];
if(!used[v])
{
used[v]=true;
if(linker[v]==-||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
}
return false;
}
int hungary()
{
int res=;
int u;
memset(linker,-,sizeof(linker));
for(u=;u<=uN;u++)
{
memset(used,false,sizeof(used));
if(dfs(u)) res++;
}
return res;
}
bool judge(int x,int y) //交叉染色法判断二分图
{
int i;
for(i=;i<EV[x].size();i++)
{
if(cnt[EV[x][i]]==)
{
cnt[EV[x][i]]=-*y;
matchs[EV[x][i]]=true;
if(!judge(EV[x][i],-*y)) return false;
}
else if(cnt[EV[x][i]]==y) return false;
}
return true;
}
bool matched()
{
int i;
memset(matchs,false,sizeof(matchs));
for(i=;i<=uN;i++)
{
if(EV[i].size()&&!matchs[i])
{
memset(cnt,,sizeof(cnt));
cnt[i]=-;
matchs[i]=true;
if(!judge(i,-)) return false;
}
}
return true;
}
int g[MAXN][MAXN];
int main()
{
int m,n;
int i,j;
int u,v;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
while(scanf("%d",&uN)!=EOF)
{
n=uN;
for(i=;i<=uN;i++)
if(EV[i].size()) EV[i].clear();
cl(g);
int id;
for(i=;i<=n;i++)
{
while(scanf("%d",&id)!=EOF&&id)
{
g[i][id]=;
}
}
for(i=;i<=n;i++)
{
for(j=i+;j<=n;j++)
{
if(!g[i][j]||!g[j][i])
{
EV[i].push_back(j);
EV[j].push_back(i);
}
}
}
if(matched())
printf("YES\n");
else printf("NO\n");
}
return ;
}
hdu 4751 2013南京赛区网络赛 二分图判断 **的更多相关文章
- hdu 4753 2013南京赛区网络赛 记忆化搜索 ****
看到范围基本可以想到dp了,处理起来有点麻烦 #include<iostream> #include<cstdio> #include<cstring> #incl ...
- hdu 4741 2013杭州赛区网络赛 dfs ***
起点忘记录了,一直wa 代码写的很整齐,看着很爽 #include<cstdio> #include<iostream> #include<algorithm> # ...
- hdu 4739 2013杭州赛区网络赛 寻找平行坐标轴的四边形 **
是平行坐标轴的,排个序搞一下就行了,卧槽,水的不行 如果不是平行的,则需要按照边长来判断
- hdu 4738 2013杭州赛区网络赛 桥+重边+连通判断 ***
题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥,使得这n座岛不连通,求最少要派多少人去. 处理重边 边在遍历的时候,第一个返回的一定是之前去的边,所以 ...
- hdu 4731 2013成都赛区网络赛 找规律
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举
- hdu 4273 2012长春赛区网络赛 三维凸包中心到最近面距离 ***
新模板 /* HDU 4273 Rescue 给一个三维凸包,求重心到表面的最短距离 模板题:三维凸包+多边形重心+点面距离 */ #include<stdio.h> #include&l ...
- hdu 4035 2011成都赛区网络赛E 概率dp ****
太吊了,反正我不会 /* HDU 4035 dp求期望的题. 题意: 有n个房间,由n-1条隧道连通起来,实际上就形成了一棵树, 从结点1出发,开始走,在每个结点i都有3种可能: 1.被杀死,回到结点 ...
- hdu 4412 2012杭州赛区网络赛 期望
虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...
- hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***
题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙, 每个逮捕队伍在每个城市可以选 ...
随机推荐
- LUA require 搜索路径指定方法
如果是一个 *.LUA 的文件, 里面用到了自己写的库, 或者第三方写的库, 但是你不想把它放到 lua 的安装目录里, 则在代码里面可以指定require搜索的路径. package.path = ...
- Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Linux设置交换分区swap
参考: http://www.vpser.net/opt/vps-add-swap.html https://www.zntec.cn/archives/vps-swap.html http://yz ...
- Solr集群更新配置的方式
solr集群中配置文件是经常更新的,频率最高的也就是schema.xml和solrconfig.xml这两个配置文件了,对于更新配置文件之前,我们先了解一下集群项目结构 由于在集群模式下,solrco ...
- ABAP 内表的行列转换-发货通知单-打印到Excel里-NEW-(以运单号为单位显示ALV然后保存输出)
*********************************************************************** * Title : ZSDF003 ...
- 数据结构-链表实现删除全部特定元素x
链表节点类定义: template <class T> class SingleList; template <class T> class Node { private: T ...
- jquery中使用event.target的几点
jquery中使用event.target的几点 1.this和event.target的区别: js中事件是会冒泡的,所以this是可以变化的,但event.target不会变化,它永远是直接接受事 ...
- JAVA回调接口的理解
A类持有B接口的对象引用,B接口有一个callBack()方法,C类是B类的实现类,实现了callBack()方法,把C类传入A类,当A类执行完操作后调用callBack()方法,这时候A调用的就是C ...
- 【leetcode】 Search a 2D Matrix (easy)
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- 如何将.il、.res文件封装成dll文件
将你的.il..res文件保存在你的硬盘上,如下图: 我存放的路径在E盘的test文件夹中,我们开始封装了咯.进入DOS命令,如下图: 我们通过DOS命令先进入.il..res文件目录,如下图: 然后 ...