博客
关于我
HDU - 1811 Rank of Tetris 并查集 + 拓扑序
阅读量:251 次
发布时间:2019-03-01

本文共 1907 字,大约阅读时间需要 6 分钟。

题意:

在这里插入图片描述
首先看到排名自然想到拓扑序,但是存在等于的情况,这就启发我们把等于的情况缩成一个点,让后在缩点后的图中进行拓扑即可。
对于不合法的情况当然是拓扑序没有遍历到应该遍历的点,所以只需要检查遍历了几个点即可。对于信息不全的情况,那就是对应同一级存在多个点,所以只需要判断队列是否恒为一个元素即可(当然这种说法不严谨)。
最后如果用并查集缩点的话,一定要注意判断 i == find(i) ,因为缩完点之后这个点就是这个集合的代表。

//#pragma GCC optimize(2)#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define X first#define Y second#define L (u<<1)#define R (u<<1|1)#define pb push_back#define mk make_pair#define Mid (tr[u].l+tr[u].r>>1)#define Len(u) (tr[u].r-tr[u].l+1)#define random(a,b) ((a)+rand()%((b)-(a)+1))#define db puts("---")using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;typedef unsigned long long ULL;typedef pair
PII;const int N=100010,M=N*2,mod=1e9+7,INF=0x3f3f3f3f;const double eps=1e-6;int n,m;int e[M],ne[M],h[N],idx;int p[N],tot;int d[N];bool st[N];struct Query{ int a,b; char op;}q[N];void add(int a,int b){ e[idx]=b,ne[idx]=h[a],h[a]=idx++;}int find(int x){ return x==p[x]? x:p[x]=find(p[x]);}int topsort(){ int sum=0,s=0; int f1,f2; f1=f2=0; queue
q; for(int i=0;i
1) f1=1; while(q.size()) { int cnt=0; sum++; int u=q.front(); q.pop(); for(int i=h[u];~i;i=ne[i]) { int j=e[i]; if(--d[j]==0) q.push(j),cnt++; } if(cnt>1) f1=1; } if(sum!=s) f2=1; if(f1&&f2) return 2; else if(f2) return 2; else if(f1) return 1; else return 0;}int main(){ // ios::sync_with_stdio(false);// cin.tie(0); while(scanf("%d%d",&n,&m)!=EOF) { idx=0; tot=0; for(int i=0;i
') d[a]++,add(b,a); else d[b]++,add(a,b); } int t=topsort(); if(t==2) puts("CONFLICT"); else if(t==1) puts("UNCERTAIN"); else puts("OK"); } return 0;}/**/

转载地址:http://nslx.baihongyu.com/

你可能感兴趣的文章
Mysql中怎样使用update更新某列的数据减去指定值
查看>>
Mysql中怎样设置指定ip远程访问连接
查看>>
mysql中数据表的基本操作很难嘛,由这个实验来带你从头走一遍
查看>>
Mysql中文乱码问题完美解决方案
查看>>
mysql中的 +号 和 CONCAT(str1,str2,...)
查看>>
Mysql中的 IFNULL 函数的详解
查看>>
mysql中的collate关键字是什么意思?
查看>>
MySql中的concat()相关函数
查看>>
mysql中的concat函数,concat_ws函数,concat_group函数之间的区别
查看>>
MySQL中的count函数
查看>>
MySQL中的DB、DBMS、SQL
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>
MySQL中的IO问题分析与优化
查看>>
MySQL中的ON DUPLICATE KEY UPDATE详解与应用
查看>>
mysql中的rbs,SharePoint RBS:即使启用了RBS,内容数据库也在不断增长
查看>>
mysql中的undo log、redo log 、binlog大致概要
查看>>
Mysql中的using
查看>>
MySQL中的关键字深入比较:UNION vs UNION ALL
查看>>
mysql中的四大运算符种类汇总20多项,用了三天三夜来整理的,还不赶快收藏
查看>>