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个大写字母,给定它们的一些关系,要求判断出经过多少个关系之后可以确定它们的排序或者排序存在冲突,或者所有的偏序关系用 ...
随机推荐
- 配置Kestrel 网址Urls
配置Kestrel 网址Urls ASP.NET Core中如何配置Kestrel Urls呢,大家可能都知道使用UseUrls() 方法来配置. 今天给介绍全面的ASP.NET Core 配置 Ur ...
- C语言日期时间标准库
用思维导图整理: 代码: #include <stdio.h> #include <time.h> #include <string.h> int main() { ...
- Visual Studio 2013 Professional Key
今天发现家里的VS2013专业版过期了,于是google百度一顿大搜,多数key都不能用,不过还是找到一个key可以使用的. Visual Studio 2013 Professional Key: ...
- 统计维护<第四篇>
SQL Server允许用户手工地控制单独数据库中的统计维护.SQL Server的4个主要的控制紫铜统计的维护的配置如下: 在无索引的列上新建统计(自动创建统计): 更新现有统计(自动更新统计): ...
- C++的ABI真特么是evil
果然有些公司明确禁止使用STL也是有一定道理的.其实这个问题的本质就是认为大部分开发者是蠢货,没水平掌控这些细节,项目Release万一出乱子了怎么办?为此吐个槽,我链接一个库时,由于编译参数和链接参 ...
- 15款免费WiFi入侵破解安全测试工具
以下是的15款免费(接近免费)的WiFi网络入侵测试工具.这些工具将帮你发现流氓AP,弱Wi-Fi密码等安全隐患,在黑客光临之前把漏洞补上. 一.Vistumbler扫描器 Kismet是一个开源的W ...
- 使用 Strace 和 GDB 调试工具的乐趣
编写 UNIX® 系统程序充满乐趣,并且具有教育意义.使用 UNIX strace 工具和 GDB(GNU 项目调试工具),您可以真正地深入研究系统的功能,并了解组成这些功能的各种各样的程序.同时使用 ...
- libeXosip2(2-1) -- eXosip2 configuration API
eXosip2 configuration API General purpose API. Data Structures struct eXosip_dns_cache struct eX ...
- CF 578A A Problem about Polyline
题意: There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - ( ...
- 分析linux下的编译环境
不论是windows下的程序,还是linux下的程序,开发环境都离不开三个目录:include.lib.bin,分别是头文件目录.库文件目录.运行文件目录.或许目录不叫这个名字,但却必不可少,除非你的 ...