题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=1811
题目概述:
中文题就略了。
大致思路:
显然这是一个拓扑排序的问题,不过题中有两个点rating相等的情况,我们发现因为不关心最后的排序结果,所以用并查集合并一下相等的点这时候就是求一个有向图的拓扑序了。
题中conflict的情况是图中有环,uncertain的情况是所求排序不唯一,此时只需要将有向图反向,再求一遍拓扑序对比一下之前求的拓扑序,如果有差异则说明情况为uncertain,否则为OK。
代码:
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include
,greater
> q; 63 for(int i=0;i
') {G[a].push_back(c);in[c]++;}107 }108 /*for(int i=0;i ') {G[c].push_back(a);in[a]++;}126 }127 re_toposort(n);128 }129 //clock_t ed=clock();130 //printf("\n\nTime Used : %.5lf Ms.\n",(double)(ed-st)/CLOCKS_PER_SEC);131 return 0;132 }