hdu-1811 Rank of Tetris 并查集+拓扑
来源:互联网 发布:windows改变图标 编辑:程序博客网 时间:2024/04/30 05:59
题目链接
#include <stdio.h>#include <string.h>#include <iostream>#include <queue>#include <vector>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 10005;const int Mod = 1000000007;int n,m,num,flag,ok;int p[maxn];int a[maxn<<1],b[maxn<<1],in[maxn];char ch[maxn<<1];vector<int>map[maxn];int find( int x ){ return p[x] == x?x:p[x] = find( p[x] );}void merge( int a,int b ){ int x = find( a ); int y = find( b ); if( x != y ) { p[x] = y; num --; }}void Topo(){ queue<int>que; for( int i = 0; i < n; i ++ ) { if( in[i] == 0 && i == find( i ) ) que.push( i ); } while( !que.empty() ) { if( que.size() > 1 ) ok = 0; int u = que.front(); que.pop(); num --; for( int i = 0; i < map[u].size(); i ++ ) { int v = map[u][i]; if( -- in[v] == 0 ) que.push( v ); } }}void init(){ flag = 0; num = n; ok = 1; for( int i = 0; i < n; i ++ ){ p[i] = i; in[i] = 0; map[i].clear(); }}int main(){ #ifndef ONLINE_JUDGE freopen("data.txt","r",stdin); #endif while( scanf("%d%d",&n,&m) != EOF ) { init(); for( int i = 1; i <= m; i ++ ) { scanf("%d %c %d",&a[i],&ch[i],&b[i]); if( ch[i] == '=' ) merge( a[i],b[i] ); } for( int i = 1; i <= m; i ++ ) { if( ch[i] == '=' ) continue; int fx = find( a[i] ); int fy = find( b[i] ); if( fx == fy ){ flag = 1; break; } if( ch[i] == '>' ) { map[fx].push_back( fy ); in[fy] ++; } else if( ch[i] == '<' ) { map[fy].push_back( fx ); in[fx] ++; } } if( flag ) printf("CONFLICT\n"); else { Topo(); if( num > 1 ) printf("CONFLICT\n"); else if( ok ) printf("OK\n"); else printf("UNCERTAIN\n"); } } return 0;}
0 0
- hdu 1811Rank of Tetris (并查集+拓扑排序)
- HDU 1811 Rank of Tetris(拓扑排序+并查集)
- HDU 1811 Rank of Tetris(拓扑排序+并查集)
- hdu-1811-Rank of Tetris-并查集+拓扑排序
- hdu 1811 Rank of Tetris (并查集+拓扑排序)
- hdu 1811 Rank of Tetris (并查集 + 拓扑排序)
- HDU 1811 Rank of Tetris(并查集+拓扑排序)
- 【HDU】1811 Rank of Tetris 并查集+拓扑排序
- hdu 1811Rank of Tetris 拓扑+并查集
- hdu-1811 Rank of Tetris 并查集+拓扑
- HDU 1811-Rank of Tetris(拓扑排序+并查集)
- HDU 1811 Rank of Tetris(并查集+拓扑排序)
- hdu 1811 Rank of Tetris 【并查集+拓扑排序】
- hdu 1811 Rank of Tetris 并查集+拓扑排序
- hdu 1811 Rank of Tetris 拓扑排序+并查集
- [HDU 1811] Rank of Tetris 并查集+拓扑
- HDU 1811 Rank of Tetris -- 并查集+拓扑排序
- [HDU 1811] Rank of Tetris (并查集+拓扑排序)
- 继承中的非虚成员函数
- Eclipse 插件
- CCI 9.4 集合的所有子集
- 看《软件测试技术大全:测试基础 流行工具 项目实践(第二版)》。。
- ios Game-Center 开发 part1
- hdu-1811 Rank of Tetris 并查集+拓扑
- Yii 不完全解决方案(一)
- 使用ubuntuliveCD重新安裝grub2
- wikioi1128 导弹拦截(理解思路)
- Android开源项目第二篇——工具库篇
- Hibernate和MySQL5.5创建表出错--'type=InnoDB'/schema export unsucessful
- hdu4937 Lucky Number,数论
- 编程之美之买票找零
- ios 局部变量,全局变量,成员变量