POJ2367拓扑排序入门
来源:互联网 发布:linux安全狗 编辑:程序博客网 时间:2024/05/22 03:52
#include <iostream>#include<stdio.h>#include<stdlib.h>#define MAX 110typedef struct nn{int data[MAX];int top;}nn;nn ms;int vis[MAX];int mp[MAX][MAX];int res[MAX];int flag,n,fla;int check(int x){ int i; for(i=0;i<=n;i++) { if(mp[i][x]==1) return 1; } return 0;}int main(){ int i,x,y,j; while(scanf("%d",&n)!=EOF) { ms.top=-1; flag=fla=0; for(x=1;x<=n;x++) for(y=1;y<=n;y++) mp[x][y]=0; for(i=1;i<=n;i++) { while(scanf("%d",&x)!=EOF&&x) { mp[i][x]=1; } } for(i=1;i<=n;i++) { if(check(i)) { ms.top++; ms.data[ms.top]=i; } else { vis[i]=1; for(j=1;j<=n;j++) { mp[i][j]=0; } res[fla++]=i; } } while(ms.top>-1) { if(check(ms.data[ms.top])==0) { for(j=1;j<=n;j++) mp[ms.data[ms.top]][j]=0; res[fla++]=ms.data[ms.top]; ms.top--; } } for(i=0;i<fla;i++) { printf("%d",res[i]); if(i==fla-1) printf("\n"); else printf(" "); } } return 0;}特别注意他输入的时候是第一行输入以1位前置的数字,这里是个大坑
0 0
- POJ2367 拓扑排序入门
- POJ2367拓扑排序入门
- poj2367 拓扑排序入门
- poj2367 拓扑排序
- POJ2367(拓扑排序)
- poj2367 拓扑排序
- POJ2367【拓扑排序】
- poj2367(拓扑排序)
- POJ2367 Genealogical tree (拓扑排序)
- 拓扑排序简单应用poj2367
- POJ2367 Genealogical tree(拓扑排序)
- poj2367 Genealogical tree【拓扑排序】
- 拓扑入门 poj2367 Genealogical tree
- 简单的拓扑排序(POJ2367)
- poj2367 Genealogical tree 拓扑排序初接触
- (拓扑排序)poj2367,Genealogical tree
- poj2367 Genealogical tree(拓扑排序:输出方案)
- 纯拓扑排序一搞poj2367
- material-calendarview日历控件
- HTML的META标签
- 杭电 2002 计算球体积
- [剑指Offer]9.用两个栈实现队列
- 点击tableViewCell,调用打电话的功能
- POJ2367拓扑排序入门
- 极客学院 java 文件的操作 代码笔记
- linux内核数据结构之kfifo
- 网络信息安全
- 僵尸木马
- 搭建Xilinx交叉编译环境
- linux svn cmd
- Eclipse快捷键 10个最有用的快捷键
- 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第十三讲:盒子的定位实例