题意:

思路:topo+并查集

 #include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>
using namespace std;
vector<int > web[];
int p[],n,m,sum,f[],A[],B[];
char C[];
bool ok;
int find(int x) {return p[x] == x ? x : p[x] = find(p[x]);}
void order(){
queue<int> q;
for ( int i = ; i < n ; ++i)
if ( f[i] == && find(i) == i )
q.push(i);
while(!q.empty()){
if ( q.size() > ) ok=true;///否则说明信息不完全
int cur = q.front();
q.pop();
sum--;
for(int i = ; i < web[cur].size() ; ++i)
{
if(--f[web[cur][i]]==)
q.push(web[cur][i]);
}
}
return ;
}
int main(){
while (scanf("%d %d",&n,&m) != EOF){
ok = false ;sum = n;
for (int i = ;i <= n;++i){
p[i] = i;
web[i].clear();
f[i] = ;
}
for (int i = ;i < m; ++i){
scanf("%d %c %d",&A[i],&C[i],&B[i]);
int x = find(A[i]),y = find(B[i]);
if (C[i] == '='){
if (x != y){
p[y] = x;
sum--;
}
}
}
for (int i = ;i < m;++i){
if (C[i] == '=') continue;
int x = find(A[i]);
int y = find(B[i]);
if (C[i] == '>'){
web[x].push_back(y);
f[y]++;
}
else {
web[y].push_back(x);
f[x]++;
}
}
order();
if (sum > ) printf("CONFLICT\n");
else if (ok) printf("UNCERTAIN\n");
else printf("OK\n");
}
return ;
}

HDU 1811 并查集的更多相关文章

  1. HDU 1811 并查集+拓扑排序

    Rank of Tetris 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1811 Problem Description 自从Lele开发了Rati ...

  2. hdu 4514 并查集+树形dp

    湫湫系列故事——设计风景线 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  3. HDU 3926 并查集 图同构简单判断 STL

    给出两个图,问你是不是同构的... 直接通过并查集建图,暴力用SET判断下子节点个数就行了. /** @Date : 2017-09-22 16:13:42 * @FileName: HDU 3926 ...

  4. HDU 4496 并查集 逆向思维

    给你n个点m条边,保证已经是个连通图,问每次按顺序去掉给定的一条边,当前的连通块数量. 与其正过来思考当前这边会不会是桥,不如倒过来在n个点即n个连通块下建图,检查其连通性,就能知道个数了 /** @ ...

  5. HDU 1232 并查集/dfs

    原题: http://acm.hdu.edu.cn/showproblem.php?pid=1232 我的第一道并查集题目,刚刚学会,我是照着<啊哈算法>这本书学会的,感觉非常通俗易懂,另 ...

  6. HDU 2860 并查集

    http://acm.hdu.edu.cn/showproblem.php?pid=2860 n个旅,k个兵,m条指令 AP 让战斗力为x的加入y旅 MG x旅y旅合并为x旅 GT 报告x旅的战斗力 ...

  7. hdu 1198 (并查集 or dfs) Farm Irrigation

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1198 有题目图11种土地块,块中的绿色线条为土地块中修好的水渠,现在一片土地由上述的各种土地块组成,需要浇 ...

  8. hdu 1598 (并查集加贪心) 速度与激情

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1598 一道带有贪心思想的并查集 所以说像二分,贪心这类基础的要掌握的很扎实才行. 用结构体数组储存公 ...

  9. hdu 4496(并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4496. 思路:简单并查集应用,从后往前算就可以了. #include<iostream> ...

随机推荐

  1. Python多进程编程

    转自:Python多进程编程 阅读目录 1. Process 2. Lock 3. Semaphore 4. Event 5. Queue 6. Pipe 7. Pool 序. multiproces ...

  2. Java 中文字符串编码之GBK转UTF-8

    写过两篇关于编码的文章了,以为自己比较了解编码了呢?! 结果今天又结结实实的上了一课. 以前转来转去解决的问题终归还是简单的情形.即iso-8859-1转utf-8,或者iso-8859-1转gbk, ...

  3. ASP.Net系列教程

    Getting Started with ASP.NET MVC This is a beginner tutorial that introduces the basics of ASP.NET M ...

  4. struts的hello world小试

    struts的hello world小试 前面jdk的安装和配置,tomcat的安装和配置以及java ide的安装和配置就不写了. 在项目中使用流程 创建一个Web项目 导如struts 2.0.1 ...

  5. Java 输入输出流 转载

    转载自:http://blog.csdn.net/hguisu/article/details/7418161 1.什么是IO Java中I/O操作主要是指使用Java进行输入,输出操作. Java所 ...

  6. CentOS6.5 mysql 5.5安装

    CentOS 6 mysql5.5安装配置 1 安装所需软件 2 安装cmake 3 tar.gz形式安装mysql 4 配置与启动 MySQL自5.5版本以后,就开始使用cmake编译工具了.tar ...

  7. js蛋疼的Class(获取class对象)

    之前处理class对象被迫用jquery,以为JavaScript不支持class.确实百度某些大神也说js不待见class对象,就这样本菜放弃了原生js. 今天偶然发现一片文章吐槽jquery拥抱J ...

  8. do while(false)实用技巧

    今天看项目源码的时候发现有些地方用了do{} while(false)的用法,查了下发现这样确实有些优点,mark下. 1.最重要的优点,用在略微复杂的宏定义中. #define AB1 a; b; ...

  9. android 破解工具

    来记录一下本人在平时工作中使用的android上的破解工具 静态破解: apktool: apk包 -> dex dex2jar和enjarify(google官方出品): dex->ja ...

  10. Ubuntu 16.04服务器安装及软件配置

    1.配置静态地址 vim /etc/network/interfaces auto enp1s0 iface enp1s0 inet static address 192.168.1.131 netm ...