题意:

思路: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. json根据key取values

    function getJson(key, jsonObj) { for (var item in jsonObj) { if (item == key) { //item 表示Json串中的属性,如 ...

  2. OS X 下iso刻录U盘

    1. 查看盘 $diskutil list /dev/disk0 #: TYPE NAME SIZE IDENTIFIER : GUID_partition_scheme *320.1 GB disk ...

  3. Cheatsheet: 2016 02.01 ~ 02.29

    Web How to do distributed locking Writing Next Generation Reusable JavaScript Modules in ECMAScript ...

  4. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:排序、筛选和分页

    这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第三篇:排序.筛选和分页 原文:Sort ...

  5. centos minimal 开启无线网卡 & 查看IP

    minimal版本默认不启动网络,所以要自己配置. 配置过程很简单,编辑配置文件 vi /etc/sysconfig/network-script/ifcfg-eth0 需要更改两项 NM_CONTR ...

  6. python uuid、hex study

    由 import uuid product[“SourceInfo"]["ProductID"] = uuid.uuid4().hex 引起的uuid 一.概述 uuid ...

  7. java高薪之路__008_Annotation

    元注解 共有4种 @Retention 表示需要在什么级别保存该注释信息(生命周期) |--- RetentionPolicy.SOURCE: 停留在java源文件,编译器被丢掉 |--- Reten ...

  8. 从原理上理解NodeJS的适用场景

    NodeJS是近年来比较火的服务端JS平台,这一方面得益于其在后端处理高并发的卓越性能,另一方面在nodeJS平台上的npm.grunt.express等强大的代码与项目管理应用崛起,几乎重新定义了前 ...

  9. SpringMVC -- 梗概--贰

    1.为什么要配置: mvc:annotation-driven 1>在springMVC的处理流程中,有两个重要组件:HandlerMapping和HandlerAdapter 分别负责解析Ha ...

  10. 张艾迪(创始人):创始人故事无限N个

    世界第一女孩+世界第一互联网女孩 创始人故事无限N个 全球第一互联网女孩EidyZhang艾迪.张 The World No.1 Girl :Eidyzhang The World No.1 Inte ...