HDU 1811 并查集
题意:
思路: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 并查集的更多相关文章
- HDU 1811 并查集+拓扑排序
Rank of Tetris 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1811 Problem Description 自从Lele开发了Rati ...
- hdu 4514 并查集+树形dp
湫湫系列故事——设计风景线 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- HDU 3926 并查集 图同构简单判断 STL
给出两个图,问你是不是同构的... 直接通过并查集建图,暴力用SET判断下子节点个数就行了. /** @Date : 2017-09-22 16:13:42 * @FileName: HDU 3926 ...
- HDU 4496 并查集 逆向思维
给你n个点m条边,保证已经是个连通图,问每次按顺序去掉给定的一条边,当前的连通块数量. 与其正过来思考当前这边会不会是桥,不如倒过来在n个点即n个连通块下建图,检查其连通性,就能知道个数了 /** @ ...
- HDU 1232 并查集/dfs
原题: http://acm.hdu.edu.cn/showproblem.php?pid=1232 我的第一道并查集题目,刚刚学会,我是照着<啊哈算法>这本书学会的,感觉非常通俗易懂,另 ...
- HDU 2860 并查集
http://acm.hdu.edu.cn/showproblem.php?pid=2860 n个旅,k个兵,m条指令 AP 让战斗力为x的加入y旅 MG x旅y旅合并为x旅 GT 报告x旅的战斗力 ...
- hdu 1198 (并查集 or dfs) Farm Irrigation
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1198 有题目图11种土地块,块中的绿色线条为土地块中修好的水渠,现在一片土地由上述的各种土地块组成,需要浇 ...
- hdu 1598 (并查集加贪心) 速度与激情
题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1598 一道带有贪心思想的并查集 所以说像二分,贪心这类基础的要掌握的很扎实才行. 用结构体数组储存公 ...
- hdu 4496(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4496. 思路:简单并查集应用,从后往前算就可以了. #include<iostream> ...
随机推荐
- 浅谈 PHP 与手机 APP 开发(API 接口开发)
本文内容转载自:http://www.thinkphp.cn/topic/5023.html 这个帖子写给不太了解PHP与API开发的人一.先简单回答两个问题:1.PHP 可以开发客户端?答:不可以, ...
- Intent 匹配规则
1.在AndroidManifest.xml中可以为 每个 Activity,Service 设置多个Intent-Filter; 在系统启动和程序安装之后,android会收集AndroidMani ...
- 复习练习(03)jquery Css方法一步步升级
jquery Css方法一步步升级 <script src="jquery-1.8.3.js"></script> <script type=&quo ...
- 关于 Oracle 的数据导入导出及 Sql Loader (sqlldr) 的用法
在 Oracle 数据库中,我们通常在不同数据库的表间记录进行复制或迁移时会用以下几种方法: 1. A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中2. 建立数据库间的 ...
- Calendar日历小程序
//有待完善,有点bugpackage com.sunshine.framework.calendar.model;import java.util.Calendar;/** * * <p> ...
- 【leetcode❤python】 414. Third Maximum Number
#-*- coding: UTF-8 -*- #l1 = ['1','3','2','3','2','1','1']#l2 = sorted(sorted(set(l1),key=l1.index,r ...
- 【leetcode❤python】 67. Add Binary
class Solution(object): def addBinary(self, a, b): """ :type a: str ...
- 在mysql数据库原有字段后增加新内容
update table set user=concat(user,$user) where xx=xxx; [注释]这个语法要求原来的字段值不能为null(可以为空字符''):
- Zero Copy
原文出处: http://www.ibm.com/developerworks/library/j-zerocopy/ 传统的I/O 使用传统的I/O程序读取文件内容, 并写入到另一个文件(或Sock ...
- jq 移除包含某个字符串的类名js
el.removeClass (function (index, css) { return (css.match (/(^|\s)star\S+/g) || []).join(' ');//移除以“ ...