poj2367 Genealogical tree(拓扑排序:输出方案)
来源:互联网 发布:mac版百度网盘没有图案 编辑:程序博客网 时间:2024/05/20 18:20
思路:模板题
一时SB忘记加!=EOF,一直OLE
#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <string>#include <set>#include <ctime>#include <cmath>#include <cctype>using namespace std;#define maxn 1000#define LL long longint cas=1,T;int n;vector<int>G[maxn];int in[maxn];int ans[maxn];void topo(){queue<int>q;for (int i = 1;i<=n;i++)if (in[i]==0)q.push(i);int cnt=0;while (!q.empty()){int u = q.front();q.pop();ans[cnt++]=u;for (int i = 0;i<G[u].size();i++){int v = G[u][i];if (--in[v]==0)q.push(v);}}}int main(){while (scanf("%d",&n)!=EOF && n){for (int i = 1;i<=n;i++){G[i].clear();in[i]=0;}for (int i = 1;i<=n;i++){ int v;while (scanf("%d",&v) && v){G[i].push_back(v);in[v]++; //记得入度要加一}}topo();printf("%d",ans[0]);for (int i = 1;i<n;i++)printf(" %d",ans[i]);//puts("");printf("\n");}//freopen("in","r",stdin);//scanf("%d",&T);//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);return 0;}
0 0
- poj2367 Genealogical tree(拓扑排序:输出方案)
- POJ2367 Genealogical tree (拓扑排序)
- POJ2367 Genealogical tree(拓扑排序)
- poj2367 Genealogical tree【拓扑排序】
- poj2367 Genealogical tree 拓扑排序初接触
- (拓扑排序)poj2367,Genealogical tree
- poj2367 Genealogical tree (裸拓扑排序)
- 拓扑入门 poj2367 Genealogical tree
- POJ2367——Genealogical tree(拓扑排序模板)
- POJ 2367 Genealogical tree(拓扑排序:输出方案)
- [学习][poj2367]拓扑序 Genealogical tree
- Genealogical tree 拓扑排序
- POJ2367 Genealogical tree
- poj2367 Genealogical tree
- POJ2367--Genealogical tree
- poj2367 Genealogical tree
- poj2367 Genealogical tree
- <poj2367>Genealogical tree
- OpenCV Android 打开前置后置摄像头
- mybatis
- HDU 3236 Gift Hunting(01背包)
- html转成pdf的方法
- 刷机命令
- poj2367 Genealogical tree(拓扑排序:输出方案)
- Canvas
- Linux shell
- Android DiskLRUCache图片下载优化 <20>
- 安装MySQL Workbench 6.3.4 CE (winx64)出错KERNELBASE.dll的解决方案
- Objective-C 的 Runtime
- Swift - 操作SQLite数据库(引用SQLite3库)
- 第九章 JSP标签——《跟我学Shiro》
- kconfig .config makefile 之间关系