思路:一开始以为rating相同的点就直接比较rp然后建图,后来想想不对,因为这样发现不了冲突。后来一想对于rating相同的点可以不用排序,因为对于这些点,他们的rp必然不相同,也就是说在这些点的内部必然存在唯一的且合理的排序,因此只需将要将这些点合并成一个点即可,需要用到并查集的知识。

把所有点按上述方法处理后就会得到一些点(暂且称为“有效点”),对于这些有效点再进行拓扑排序即可。

冲突情形:到最后存在环,或者出现a > b,b > c 且 c >a;

不确定情形:同一层中不止一个点入度为0;

确定情形:除以上两种情形;

#include<stdio.h>
#include<string.h>
typedef struct
{
int to;
int next;
}EdgeNode;
int cnt;
char str[6];
EdgeNode Edge[20005];
int father[10005],depth[10005];
int L[10005],M[10005],R[10005];
int head[10005],indegree[10005];
int vis[10005],node[10005],temp[10005];
void init(int n)
{
int i;
cnt = 0;
memset(vis,0,sizeof(vis));
memset(head,-1,sizeof(head));
memset(indegree,0,sizeof(indegree));
for(i = 0;i < n;i ++)
{
father[i] = i;
depth[i] = 0;
}
} int find(int x)
{
if(x == father[x])
return x;
return father[x] = find(father[x]);
} void uint(int x,int y)
{
x = find(x);
y = find(y);
if(x == y)
return ;
if(depth[x] < depth[y])
father[x] = y;
else
{
if(depth[x] > depth[y])
father[y] = x;
else
{
father[x] = y;
depth[y]++;
}
}
return ;
} void add_edge(int n,int m)
{
Edge[cnt].to = m;
Edge[cnt].next = head[n];
head[n] = cnt++;
} int main(void)
{
int a,b,n,m,i,j,k;
int sum,flag_U,flag_C;
while(~scanf("%d %d",&n,&m))
{
init(n);
flag_U = flag_C = 0;
for(i = 1;i <= m;i ++)
{
scanf("%d %c %d",&L[i],&M[i],&R[i]);
if(M[i] == '=')
{
uint(L[i],R[i]);
}
}
for(i = 1;i <= m;i ++)
{
if(M[i] == '=')
continue ;
a = find(L[i]);
b = find(R[i]);
if(a == b)
{
flag_C = 1;
break ;
}
else
{
if(M[i] == '>')
{
add_edge(b+1,a+1);
indegree[a+1]++;
}
else
{
add_edge(a+1,b+1);
indegree[b+1]++;
}
}
}
for(i = 1;i <= n;i ++)
{
sum = 0;
for(j = 1;j <= n;j ++)
{
if(indegree[j] == 0 && vis[j] == 0 && father[j-1] == j-1)
temp[sum++] = j;
}
if(sum > 1)
flag_U = 1;
for(j = 0;j < sum;j ++)
{
vis[temp[j]] = 1;
for(k = head[temp[j]];k != -1;k = Edge[k].next)
{
if(!vis[Edge[k].to])
indegree[Edge[k].to]--;
}
}
}
for(i = 1;i <= n;i ++)
{
if(indegree[i] && father[i-1] == i-1)
{
flag_C = 1;
break ;
}
}
if(!(flag_C+flag_U))
printf("OK\n");
if(flag_C)
printf("CONFLICT\n");
if(flag_U && !flag_C)
printf("UNCERTAIN\n");
}
return 0;
}

HDU 1881的更多相关文章

  1. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. PHP的PSR-0命名标准

    PSR是Proposing a Standards Recommendation(提出标准建议)的缩写,是由PHP Framework Interoperability Group(PHP通用性框架小 ...

  2. 《编写高质量代码:改善Python程序的91个建议》读后感

    编写高质量代码:改善Python程序的91个建议  http://book.douban.com/subject/25910544/ 1.(建议16)is 用于判断两个对象的id是否相等,==才是判断 ...

  3. 【配置文件节点】java世界配置文件节点

    Spring <context:property-placeholder/> 期望:能不能有一种解决方案可以方便我们在一个阶段内不需要频繁书写一个参数的值,而在不同阶段间又可以方便的切换参 ...

  4. 【spring配置】 一组配置文件引出的问题

    applicationContext.xml: <?xml version="1.0" encoding="UTF-8"?> <beans x ...

  5. CSS的绝对定位和相对定位

    css定位标签position包括两个值:relative(相对定位)和absolute(绝对定位),position样式一般都是和top.bottom.left.right一起使用来确定一个标签的位 ...

  6. 判断js中各种数据的类型方法之typeof与0bject.prototype.toString讲解

    提醒大家,Object.prototype.toString().call(param)返回的[object class]中class首字母是大写,像JSON这种甚至都是大写,所以,大家判断的时候可以 ...

  7. Weex详解:灵活的移动端高性能动态化方案

    原文地址:http://www.infoq.com/cn/articles/introducing-weex 在2016年4月份的QCon上,阿里巴巴资深总监,淘宝移动平台及新业务事业部.阿里百川负责 ...

  8. Firefly 配置说明

    下图一一个典型的config.json的配置:配置中主要包括四个部分,master,servers,db,memcached.master用来定义master的端口,servers用来定义各个服务器中 ...

  9. POJ 2195 Going Home(最小费用最大流)

    http://poj.org/problem?id=2195 题意 :  N*M的点阵中,有N个人,N个房子.让x个人走到这x个房子中,只能上下左右走,每个人每走一步就花1美元,问当所有的人都归位了之 ...

  10. mysql 监控工具monyog使用总结

    1. 下载安装 2. 登录之后,查看 locked queries 2. 慢查询