2-SAT,根据题意建好图,求一下强联通分量,判断一下就可以了

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<algorithm>
using namespace std;const int maxn=6005;int T,M;
vector<int>G[maxn];
vector<int>FG[maxn];int Belong[maxn],flag[maxn];
stack<int>S;
int Block;void init()
{if(!S.empty()) S.pop();for(int i=0; i<maxn; i++) G[i].clear();for(int i=0; i<maxn; i++) FG[i].clear();memset(Belong,0,sizeof Belong);memset(flag,0,sizeof flag);Block=0;
}void dfs1(int now)
{flag[now]=1;for(int i=0; i<G[now].size(); i++)if(!flag[G[now][i]])dfs1(G[now][i]);S.push(now);
}void dfs2(int now)
{Belong[now]=Block;for(int i=0; i<FG[now].size(); i++)if(!Belong[FG[now][i]])dfs2(FG[now][i]);
}void Add(int x,int y)
{G[x].push_back(y);FG[y].push_back(x);
}int main()
{while(~scanf("%d%d",&T,&M)){init();for(int i=0; i<T; i++){int a,b,c;scanf("%d%d%d",&a,&b,&c);Add(3*T+a,b);Add(3*T+a,c);Add(3*T+b,a);Add(3*T+c,a);}for(int i=0; i<M; i++){int a,b;scanf("%d%d",&a,&b);Add(a,3*T+b);Add(b,3*T+a);}for(int i=0; i<6*T; i++) if(!flag[i]) dfs1(i);while(!S.empty()){int Top=S.top();S.pop();if(!Belong[Top]){Block++;dfs2(Top);}}int ans=1;for(int i=0; i<3*T; i++){if(Belong[i]==Belong[3*T+i]){ans=0;break;}}if(ans==1) printf("yes\n");else printf("no\n");}return 0;
}

转载于:https://www.cnblogs.com/zufezzt/p/4904464.html

HDU 1824 Let's go home相关推荐

  1. hdu 1824 Let's go home(2-sat 基础题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1824 小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头.                       ...

  2. (2 sat) hdu 1824

    Let's go home Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. 图论--2-SAT--HDOJ/HDU 1824 Let's go home

    Problem Description 小时候,乡愁是一枚小小的邮票,我在这头,母亲在那头.                         -- 余光中 集训是辛苦的,道路是坎坷的,休息还是必须的. ...

  4. [2-sat专练]poj 3683,hdu 1814,hdu 1824,hdu 3622,hdu 4115,hdu 4421

    文章目录 Priest John's Busiest Day code Peaceful Commission code Let's go home code Bomb Game code Elimi ...

  5. HDU 1824 Let's go home

    B - Let's go home Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB  ...

  6. HDU - 1824 Let's go home

    Let's go home Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. [kuangbin]各种各样的题单

    [kuangbin]各种各样的题单 专题1 简单搜索 POJ 1321 POJ 2251 POJ 3278 POJ 3279 POJ 1426 POJ 3126 POJ 3087 POJ 3414 F ...

  8. (转)2-sat 专题

    [2-sat]专题- 2-sat是一个逻辑性很强的算法,但是其套路比较固定,所以不是很热,题目很少,但也不乏AC后让人大呼爽快的好题,下面放出两篇极品论文还有几道题目的题解以供交流-- 2-sat学习 ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

最新文章

  1. python queue 多进程_python中的Queue与多进程(multiprocessing)
  2. [Leetcode]50. Pow(x, n)
  3. 63.2. 配置 Postfix
  4. 怎么解决相位抵消_【录音教程】如何防止话筒拾音的声学相位抵消
  5. java父类调用子类方法_Java 中父类怎么调用子类的方法?
  6. java 基础编程题 5
  7. 摩托罗拉G7系列发布:G7 Plus还有中国红配色
  8. Maven : error: missing or invalid dependency detected while loading class file 'RDD.class'
  9. 使用Google-Colab训练PyTorch神经网络
  10. 计算机专业新手博客,【转载】学计算机必读献给计算机专业大一新生(1)
  11. Vitamio不支持特性列表(本文会持续更新 2013-03-13)
  12. lfs库下载_git-lfs插件
  13. 南京邮电大学网络信息安全——软件漏洞分析与防范(实验一——栈溢出和gs保护机制)
  14. 申请德国农工大学计算机案例,德州农工大学本科案例
  15. Ubuntu 终端窗口操作快捷键
  16. 成功解决:免费使用Pycharm专业版
  17. 玩转无线路由之DD-WRT基础扫盲
  18. 解决 Successfully created project '' on GitHub, but initial push failed: Could not read from remote
  19. 微信开通检测无需等待准确高的软件
  20. CSS学习笔记7—盒子模型

热门文章

  1. centos 安装 openfire
  2. 「小程序JAVA实战」小程序头像图片上传(下)(45)
  3. Eclipse的安装与使用
  4. 《背包问题》 动态规划
  5. python 导入 包
  6. CyberArticle(网文快捕)上传文件提示‘许可不足’
  7. 在Ubuntu中使用远程桌面
  8. Android更换RatingBar图片 参考-Pretty RatingBar
  9. 简单的批处理命令(一)
  10. Android开发环境的搭建