Rank of Tetris(topsort)
http://acm.hdu.edu.cn/showproblem.php?pid=1811
#include <stdio.h>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
const int N=;
vector<int>V[N];
queue<int>q;
char oper[N];
int in[N],f[N];
int a[N],b[N];
int n,m,sum;
void init()
{
sum = n;
while(!q.empty()) q.pop();
for (int i = ; i <= n; i++)
{
f[i] = i;
in[i] = ;
V[i].clear();
}
}
int Find(int x)
{
if(x!=f[x]) return f[x]=Find(f[x]);
return x;
}
int Merge(int x,int y)
{
x = Find(x);
y = Find(y);
if(x!=y)
{
f[y] = x;
return ;
}
return ;
}
void toposort()
{
int flag = ;
for (int i = ; i < n; i++)
{
if(in[i]==&&Find(i)==i)
q.push(i);
}
while(!q.empty())
{
if (q.size()>)flag = ;
int u = q.front();
q.pop();
sum--;
for (int i = ; i < V[u].size(); i++)
{
if(--in[V[u][i]]==)
q.push(V[u][i]);
}
}
if (sum > ) printf("CONFLICT\n");
else if (flag) printf("UNCERTAIN\n");
else printf("OK\n");
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
init();
int u,v;
for (int i = ; i < m; i++)
{
scanf("%d %c %d",&a[i],&oper[i],&b[i]);
if(oper[i]=='=')
{
if(Merge(a[i],b[i]))
sum--;
}
}
for (int i = ; i < m; i++)
{
if(oper[i]=='=') continue;
u = Find(a[i]);
v = Find(b[i]);
if(oper[i]=='>')
{
V[u].push_back(v);
in[v]++;
}
if(oper[i]=='<')
{
V[v].push_back(u);
in[u]++;
}
}
toposort();
}
return ;
}
Rank of Tetris(topsort)的更多相关文章
- HDU 1811 Rank of Tetris(拓扑排序+并查集)
题目链接: 传送门 Rank of Tetris Time Limit: 1000MS Memory Limit: 32768 K Description 自从Lele开发了Rating系统, ...
- ACM: hdu 1811 Rank of Tetris - 拓扑排序-并查集-离线
hdu 1811 Rank of Tetris Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu 1811 Rank of Tetris (并查集+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Rank of Tetris HDU--1881
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1811 Rank of Tetris 拓补排序+并查集
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [ ...
- Rank of Tetris
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1811 Rank of Tetris(并查集+拓扑排序 非常经典)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1811 Rank of Tetris (拓扑 & 并查集)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1811 Rank of Tetris(并查集按秩合并+拓扑排序)
Rank of Tetris Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
随机推荐
- ie6,ie7,ie8,FF 浏览器兼容问题
javascript部分 1. document.form.item 问题问题:代码中存在 document.formName.item("itemName") 这样的语句,不能在 ...
- UVA - 11175 From D to E and Back(思路)
题目: 思路: 如图E:图中a.b.c.d是有向图D中的顶点,如果ac.bc都指向cd,而ac又指向ce,那bc同样应该有一条指向ce的边不然就不能从图D转换来.所以直接枚举顶点就可以了. 代码: # ...
- react-router v4 学习实践
最近学习了 react-router v4,根据官方 API 文档和网上资源做了一个简单的路由示例. 先用官方的工具 create-react-app 初始化一个 react 项目模板,再根据自己的 ...
- 挂载本地file到容器中
-v /Us……/cts/fffen:/usr/local/src -v 标记 将本地主机的目录 到 目标容器的路径下 在容器中查看:ls 发现已经存在py文件 运行python fenci.py ...
- BZOJ 3993 Luogu P3324 [SDOI2015]星际战争 (最大流、二分答案)
字符串终于告一段落了! 题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=3993 (luogu) https://www.l ...
- Apache Maven Cookbook(一)maven 使用命令创建、编译java项目
一.创建 使用命令创建项目分几步: 1.打开命令行窗口,比如cmd,把目录切换至想要创建项目地方. 2.执行如下命令: mvn archetype:generate -DgroupId=com.zua ...
- Adobe AIR 代码签名证书使用指南
Symantec,Thawte,GlobalSign 签发的代码签名证书都可以签名AIR文件.如果您还没有代码签名证书,请联系易维信(EVTrust)购买Adobe AIR 代码签名证书. 1.签名工 ...
- 【05】AngularJS 指令
AngularJS 指令 AngularJS 通过被称为 指令 的新属性来扩展 HTML. AngularJS 指令 AngularJS 指令是扩展的 HTML 属性,带有前缀 ng-. ng-app ...
- codevs3410 别墅房间
题目描述 Description 小浣熊松松到他的朋友家别墅去玩,发现他朋友的家非常大,而且布局很奇怪.具体来说,朋友家的别墅可以被看做一个N*M的矩形,有墙壁的地方被标记为’#’,其他地方被标记为’ ...
- zoj——1311 Network
Network Time Limit: 2 Seconds Memory Limit: 65536 KB A Telephone Line Company (TLC) is establis ...