设为首页 加入收藏

TOP

BZOJ 2079 Poi2010 Guilds 并查集
2015-07-20 17:21:13 来源: 作者: 【 】 浏览:4
Tags:BZOJ 2079 Poi2010 Guilds 查集

题目大意:给定一个无向图,要求将一些点红黑染色,使每个点及其相连的点中至少有一个黑色的点和一个红色的点

逗比题ぽい~

对于任意一个大小>=2的连通图,我们只需要搞出这个图的任意一棵生成树,将这棵生成树撸成二分图再染色就一定能满足要求的ぽい~

因此无法满足要求当且仅当存在一个大小为1的联通块ぽい~

并查集即可ぽい~

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #define M 200200 using namespace std; int n,m; namespace Union_Find_Set{ int fa[M],size[M]; int Find(int x) { if(!fa[x]) fa[x]=x,size[x]=1; if(fa[x]==x) return x; return fa[x]=Find(fa[x]); } void Union(int x,int y) { x=Find(x);y=Find(y); if(x==y) return ; fa[x]=y;size[y]+=size[x]; } } int main() { using namespace Union_Find_Set; int i,x,y; cin>>n>>m; for(i=1;i<=m;i++) { scanf("%d%d",&x,&y); Union(x,y); } for(i=1;i<=n;i++) if(size[Find(i)]==1) return cout<<"NIE"<
      
       

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 2828 Buy Tickets 万能的线段.. 下一篇LeetCode:Merge Sorted Array

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)
·使用华为开发者空间 (2025-12-27 04:19:24)
·Getting Started wit (2025-12-27 03:49:24)
·Ubuntu 上最好用的中 (2025-12-27 03:49:20)