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个大写字母,给定它们的一些关系,要求判断出经过多少个关系之后可以确定它们的排序或者排序存在冲突,或者所有的偏序关系用 ...
随机推荐
- ecstore使用paypal支付显示不支持此支付
问题描述: ecstore使用paypal支付,下单结算时显示不支持此支付. 问题和代码分析: 1.首先必须要保证默认货币是paypal支持的货币,paypal目前支付 ["supportC ...
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
说法一: 我们在运行xcode工程时,有时候会遇到”libc++abi.dylib: terminate_handler unexpectedly threw an exception”错误,app莫 ...
- .NET抽象工厂模式微理解--教你在项目中实现抽象工厂
.NET抽象工厂模式微理解--教你在项目中实现抽象工厂 最近在学习MVC,对于MVC里面的一些项目上的东西都和抽象模式有关,今天就微说明一下个人对于抽象工厂模式的理解,以方便学习MVC及工厂模式相关的 ...
- LeetCode_Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- Mysql 插入记录时检查记录是否已经存在,存在则更新,不存在则插入记录SQL
我们在开发数据库相关的逻辑过程中, 经常检查表中是否已经存在这样的一条记录, 如果存在则更新或者不做操作, 如果没有存在记录,则需要插入一条新的记录. 这样的逻辑固然可以通过两条sql语句完成. SE ...
- Windows 1252和ISO 8859-1之间的区别(ISO 8859-1就是Latin-1,但1252与Latin1略有不同)
2.6.5. ANSI字符编码和Windows 1252 Windows为了支持英语和西欧字符,自己设计了一个编码,对应的在Code Page号是1252,被称为Windows 1252. Windo ...
- Eclipse vim插件安装使用
在eclipse移动关闭位置感觉非常不爽,经常要用到方向键和鼠标,导致经常要移来移去.果断受不了了,去网上搜了下发现eclipse有许多vim插件可以使用.有一个大家都比较推荐的是 vrapper ...
- repter导出到Excel
; , * ); sheet1.SetColumnWidth(, * ); sheet1.SetC ...
- Razor Generator 将cshtml自动生成对应的CS文件
- C# 判断两个日期是否是同一天
System.Data.Entity.DbFunctions.DiffDays(cs.StartTime.Value,DateTime.Now) == 0//只获取当天 OR XX.StartTime ...