POJ1094 拓扑排序
//Memory: 224K Time: 0MS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
;
bool g[maxn][maxn];
int indegree[maxn];
int in[maxn];
int vis[maxn];
int flag;
int n, m;
int out[maxn];
string s;
int size;
int ans;
int topologicalSort()
{
memset(vis, , sizeof(vis));
memcpy(in, indegree, sizeof(in));
size = ;
flag = ;
while (size < n){
;
int next;
; i < n; i++){
if (vis[i]) continue;
) {
num++;
) break;
next = i;
}
}
) ;
else {
out[size++] = next;
vis[next] = ;
; i < n; i++) {
if ( g[next][i] && !vis[i] )
in[i]--;
}
)
flag = ;
}
}
) ;
;
}
int main()
{
while (cin >> n >> m && n) {
memset(g, , sizeof(g));
memset(indegree, , sizeof(indegree));
ans = ;
; i < m; i++){
cin >> s;
) continue;
] - ] - 'A']) {
g[s[] - ] - ;
indegree[s[] - 'A']++;
ans = topologicalSort();
) {
cout << <<" relations." << endl;
}
){
cout << << " relations: ";
; i < n; i++)
cout << (char)(out[i] + 'A');
cout << "." << endl;
}
}
}
)
cout << "Sorted sequence cannot be determined." << endl;
}
;
}
POJ1094 拓扑排序的更多相关文章
- POJ1094——拓扑排序和它的唯一性
比较模板的topological-sort题,关键在于每个元素都严格存在唯一的大小关系,而一般的拓扑排序只给出一个可能解,这就需要每趟排序的过程中监视它是不是总坚持一条唯一的路径. 算法导论里面的拓扑 ...
- poj1094拓扑排序
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29539 Accepted: 10 ...
- poj1094 拓扑排序(出度入度简单使用)
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37764 Accepted: 13 ...
- nyoj349 poj1094 Sorting It All Out(拓扑排序)
nyoj349 http://acm.nyist.net/JudgeOnline/problem.php?pid=349poj1094 http://poj.org/problem?id=10 ...
- [poj1094]Sorting It All Out_拓扑排序
Sorting It All Out poj-1094 题目大意:给出一些字符串之间的大小关系,问能否得到一个唯一的字符串序列,满足权值随下标递增. 注释:最多26个字母,均为大写. 想法:显然,很容 ...
- POJ1094 Sorting It All Out —— 拓扑排序
题目链接:http://poj.org/problem?id=1094 Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Tot ...
- POJ1094 字母排序(拓扑排序)
该题题意明确,就是给定一组字母的大小关系判断他们是否能组成唯一的拓扑序列.是典型的拓扑排序,但输出格式上确有三种形式: 1.该字母序列有序,并依次输出: 2.该序列不能判断是否有序: 3.该序列字母次 ...
- ACM/ICPC 之 拓扑排序范例(POJ1094-POJ2585)
两道拓扑排序问题的范例,用拓扑排序解决的实质是一个单向关系问题 POJ1094(ZOJ1060)-Sortng It All Out 题意简单,但需要考虑的地方很多,因此很容易将code写繁琐了,会给 ...
- POJ - 1094 Sorting It All Out(拓扑排序)
https://vjudge.net/problem/POJ-1094 题意 对于N个大写字母,给定它们的一些关系,要求判断出经过多少个关系之后可以确定它们的排序或者排序存在冲突,或者所有的偏序关系用 ...
随机推荐
- IE CSS Bug 系列
1.[IE CSS Bug系列]IE6&IE7图片链接无效 <!doctype html> <html> <head> <meta charset=& ...
- [转载]移动终端浏览器初始设置apple-mobile-web-app-capable
这两句话的确很有用,有了它,手机访问的时候像样了. 原文地址:移动终端浏览器初始设置apple-mobile-web-app-capable作者:素水凌心 移动终端浏览器默认设置视口的宽度和初始规模. ...
- silverlight中使用Json读取数据
假定按照 如何:对基于 HTTP 的服务发出请求中描述的方法向基于 HTTP 的 Web 服务发出请求后,在 Stream 类型的 responseStream 对象中返回了下列 JSON. {&qu ...
- 开源日志系统 log4c 使用心得+总结
http://blog.csdn.net/sky_qing/article/details/7208645 一.安装: 我看网上好多人介绍log4c安装的时候都说有两个步骤:先下载expat安装包并安 ...
- VLSI和ASIC的区别(转)
VLSI和ASIC是不同的两个概念 VLSI(Very Large Scale Integrate circuit)是指集成电路的规模,有时也指制造集成电路所使用的工艺,VLSI工艺一般都在1um以下 ...
- Extjs4.0.7 MVC Architecture异常
uncaught exception: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Mi ...
- nm和readelf命令的区别
其实问题的本质是对elf格式的理解问题,因为是查看so库的符号表发现的问题. 事情起因是这样的,由于我的一个程序编译的时候出现了undefined reference to “XXX”的错误,需要链接 ...
- c++ 04
一.this指针 1. 2.应用场景 1) 2)将this指针作为函数的参数.一个对象可以通知另一个对象有关自身的地址. 教师 提问|^ V|答案 学生 交叉类问题: class ...
- flex渐变色制作圆角橙色按钮
<?xml version="1.0" encoding="utf-8"?> <s:SparkButtonSkin xmlns:fx=&quo ...
- SQUEEZENET: ALEXNET-LEVEL ACCURACY WITH 50X FEWER PARAMETERS AND <0.5MB MODEL SIZE
论文阅读笔记 转载请注明出处: http://www.cnblogs.com/sysuzyq/p/6186518.html By 少侠阿朱