poj 2367 拓扑排序
来源:互联网 发布:姗姗手账小铺 淘宝 编辑:程序博客网 时间:2024/05/20 04:08
传送门
题意:我表示没看完,看输入输出就猜出意思了。
思路:根据拓扑排序随便输出可行序列。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;int n,fst[105],next[10000],node[10000];int en,in[105],ans[105],num;void add(int u,int v){ next[en]=fst[u]; fst[u]=en; node[en]=v; en++;}void topsort(){ queue<int>q; for(int i=1;i<=n;i++) { if(in[i]==0)q.push(i); } while(!q.empty()) { int u=q.front(); ans[num++]=u; q.pop(); for(int i=fst[u];i!=-1;i=next[i]) { int v=node[i]; in[v]--; if(in[v]==0)q.push(v); } }}int main(){ int u,v; en=0; num=0; memset(in,0,sizeof(in)); memset(fst,-1,sizeof(fst)); scanf("%d",&n); for(int i=1;i<=n;i++) { while(scanf("%d",&u)) { if(u==0)break; add(i,u); in[u]++; } } topsort(); printf("%d",ans[0]); for(int i=1;i<n;i++)printf(" %d",ans[i]); printf("\n"); return 0;}
- poj 2367 拓扑排序
- poj 2367 拓扑排序
- poj 2367 拓扑排序
- POJ 2367 拓扑排序
- POJ 2367 拓扑排序
- poj 2367拓扑排序
- poj 2367 拓扑排序
- 拓扑排序---(poj 2367)
- poj 2367(拓扑排序TopSort)
- 拓扑排序(poj 2367)
- POJ 2367 Genealogical tree 拓扑排序
- POJ 2367 Genealogical tree [拓扑排序]
- Poj 2367 Genealogical tree(拓扑排序)
- 【POJ】2367 Genealogical tree 拓扑排序
- POJ 2367:Genealogical tree(拓扑排序)
- POJ 2367 Genealogical tree 拓扑排序入门
- POJ 2367 Genealogical tree 拓扑排序
- POJ 2367 Genealogical tree(拓扑排序)
- Linux用户及权限基础 3---- Linux扩展权限
- Android常用控件之SeekBar的使用
- 创建线程的3种方式
- STL 容器简介:C++ 容器:顺序性容器、关联式容器和容器适配器
- 写在开始的话
- poj 2367 拓扑排序
- ImageView随手势变化 动态缩放
- 我的第一个JSP文件
- jni入门教程之HelloWorld
- paip.输入法编程--词频调整原则--发音长度优先
- Java连接Oracle笔记
- 《Windows核心编程》第二讲 Unicode(2)成为符合ANSI和Unicode的应用程序
- java 对数组进行插入删除修改
- 寻找正在连接中的网络连接,并开启网络连接的网络连接共享功能