hdu 3478 Catch--二分图判断
我觉得,给了初始点的话用bfs方便点,没有则dfs ||可能超片面
https://vjudge.net/contest/281085?tdsourcetag=s_pcqq_aiomsg#problem/C
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<set>
#include<cctype>
#include<sstream>
#define mem(a) memset(a,0,sizeof(a))
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
const int N=1e5+;
int color[N],fa[N];
int n,m,now;
vector<int> link[N];
queue<int> q;
int bfs()
{
memset(color,-,sizeof(color));
color[now]=;
while(!q.empty())
{
int k=q.front();
q.pop();
for(size_t i=;i<link[k].size();i++)
{
int t=link[k][i]; //表示定点k通过i边连接的点
if(color[t]==color[k]) //染色是否相同
return ;
if(color[t]==-)
{
q.push(t);
color[t]=-color[k];//1||0
}
}
}
return ;
}
int main()
{
int a,b,t;
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d%d%d",&n,&m,&now); for(int j=;j<n;j++)
link[j].clear(); for(int j=;j<m;j++)
{
scanf("%d %d",&a,&b);
link[a].push_back(b);
link[b].push_back(a);
} while(!q.empty())
q.pop(); q.push(now); if(!bfs()) //不是二分图,输出yes
printf("Case %d: NO\n",i);
else
printf("Case %d: YES\n",i);
}
return ;
}
hdu 3478 Catch--二分图判断的更多相关文章
- hdu 3478 Catch 二分图染色
题目链接 题意 小偷逃跑,从某个点出发,每下一个时刻能够跑到与当前点相邻的点. 问是否存在某一个时刻,小偷可能在图中的任意一个点出现. 思路 结论 如果该图为连通图且不为二分图,则可能,否则不可能. ...
- HDU 3478 Catch (连通性&&二分图判断)
链接 [https://vjudge.net/contest/281085#problem/C] 题意 一个n个点,m条边的图,开始的点是s 每次必须移动到相邻的位置,问你是否存在某个时刻所有点都可能 ...
- HDU - 3478 Catch(判奇环/二分图)
http://acm.hdu.edu.cn/showproblem.php?pid=3478 题意 给一个无向图和小偷的起点,小偷每秒可以向相邻的点出发,问有没有一个时间点小偷可能出现在任何点. 分析 ...
- hdoj 3478 Catch(二分图判定+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...
- hdu 3478 Catch(染色 dfs 或 bfs )
Problem Description A thief is running away! We can consider the city to N–. The tricky thief starts ...
- HDU 2717 Catch That Cow --- BFS
HDU 2717 题目大意:在x坐标上,农夫在n,牛在k.农夫每次可以移动到n-1, n+1, n*2的点.求最少到达k的步数. 思路:从起点开始,分别按x-1,x+1,2*x三个方向进行BFS,最先 ...
- hdu 4751 2013南京赛区网络赛 二分图判断 **
和以前做过的一个二分图颇为相似,以前的是互相不认识的放在一组,这个是互相认识的,本质上是相同的 是 hdu 2444 #include<cstdio> #include<iostre ...
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- HDU 2444 - The Accomodation of Students - [二分图判断][匈牙利算法模板]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others) Mem ...
随机推荐
- KFold,StratifiedKFold k折交叉切分
python风控评分卡建模和风控常识(博客主亲自录制视频教程) https://study.163.com/course/introduction.htm?courseId=1005214003&am ...
- socket(TCP)通讯之Python实现
1.Service address = ('localhost', 9102) # AF_INET = ipv4; SOCK_STREAM:TCP s = socket.socket(socket.A ...
- zipline-- 开发指南
Development Guidelines开发指南This page is intended for developers of Zipline, people who want to contri ...
- ccf 201903-5 317任务
[题目背景]“你在平原上走着走着,突然迎面遇到一堵墙,这墙向上无限高,向下无限深,向左无限远,向右无限远,这墙是什么?”——<流浪地球>原著我们带着地球去流浪了,为了处理流浪过程中可能会发 ...
- 第30月第18天 autolayout代码
1.上下左右 [tipsLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; { id view1 = tipsLabel; id view2 ...
- Linux命令--tree
目录 tree 最常用 带颜色显示2级目录 排除显示某个目录 tree tree -C :颜色显示 tree -f : 显示文件全路径 tree -L 2 :只显示2层 tree -P *.pl :只 ...
- go [第一篇]初识
[第一篇] 简介 Go 是一个开源的编程语言,它能让构造简单.可靠且高效的软件变得容易. Go是从2007年末由Robert Griesemer, Rob Pike, Ken Thompson主持开发 ...
- httpClient closeableHttpClient
https://www.cnblogs.com/lyy-2016/p/6388663.html
- Redis代码——Python篇
需要安装的库:redis import redis # 连接数据库 r = redis.StrictRedis(host="localhost", port=6379, passw ...
- 开源mall学习
https://github.com/macrozheng/mall 学习知识点 1.Spring Security 2.@Aspect 3.logstash 4. es crud templete ...