博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ACM模板——二分图
阅读量:4565 次
发布时间:2019-06-08

本文共 634 字,大约阅读时间需要 2 分钟。

#define pb push_back#define _for(i,a,b) for(int i = (a);i < (b);i ++)const int maxn = 50003; vector
G[maxn];int V;int color[maxn];bool dfs(int v,int c){ color[v] = c; for(int i = 0;i < G[v].size();i ++) { if(color[G[v][i]] == c) return false; if(color[G[v][i]] == 0 && !dfs(G[v][i],-c)) return false; } return true;}int biGraph(){ memset(color,0,sizeof(color)); for(int i = 0;i < V;i ++) if(color[i]==0) if(!dfs(i,1)) return 0; return 1;}
二分图

biGraph()若返回0,则不能构成二分图,返回1则能。color数组里装的是每个节点的颜色。

转载于:https://www.cnblogs.com/Asurudo/p/10493642.html

你可能感兴趣的文章
Git(介绍和安装)
查看>>
磁盘管理
查看>>
重写与重载
查看>>
Python 爬取qqmusic音乐url并批量下载
查看>>
Java代码获取spring 容器的bean几种方式
查看>>
2015年3月5日(元宵节)——substr()与substring()的区别
查看>>
mysql 导出查询结果到文件
查看>>
Js参数值中含有单引号或双引号解决办法
查看>>
python5
查看>>
js转换/Date(........)/
查看>>
mysql中limit用法
查看>>
C#开源爬虫NCrawler源代码解读以及将其移植到python3.2(1)
查看>>
c++ std::thread + lambda 实现计时器
查看>>
NSRunLoop个人理解
查看>>
BZOJ_1031_[JSOI2007]_字符串加密_(后缀数组)
查看>>
[osg]osg窗口显示和单屏幕显示
查看>>
前端技术在线文档地址链接
查看>>
077_打印各种时间格式
查看>>
[LeetCode] 101. Symmetric Tree_ Easy tag: BFS
查看>>
前端基础之html
查看>>