POJ 2367 Genealogical tree【拓普排序】
来源:互联网 发布:淘宝刷手怎么找商家 编辑:程序博客网 时间:2024/04/29 21:09
题目链接
前向星写法
#include<cstdio>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<queue>#include<vector>using namespace std;#define V 1000struct node { int v; int next;};node edge[V*4];int head[V],deg[V];int cnt;void topsort(int n){ priority_queue<int,vector<int>,greater<int> >que; for(int i=1;i<=n;i++){ if(deg[i]==0){ que.push(i); deg[i]=-1; } } int k=1; while(que.empty()==false){ int u=que.top(); que.pop(); printf("%d",u); if(k++==n)printf("\n"); else printf(" "); for(int i=head[u];i!=-1;i=edge[i].next){ node e=edge[i]; deg[e.v]--; if(deg[e.v]==0){ que.push(e.v); } } }}int main(){ int i; int n; memset(head,-1,sizeof(head)); memset(deg,0,sizeof(deg)); scanf("%d",&n); cnt = 0; for(int u=1,v;u<=n;u++){ while(scanf("%d",&v)&&v){ for(i=head[u];i!=-1;i=edge[i].next){ if(edge[i].v==v){ break; } } if(i==-1){ deg[v]++; edge[cnt].v=v; edge[cnt].next=head[u]; head[u]=cnt++; } } } topsort(n); return 0;}
0 0
- 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 拓扑排序
- POJ 2367 Genealogical tree(拓扑排序)
- POJ 2367Genealogical tree 简单拓扑排序
- poj 2367 Genealogical tree 【基础拓扑排序】
- POJ 2367 -- Genealogical tree【拓扑排序 && 水题】
- POJ 2367 Genealogical tree(拓扑排序)
- POJ-2367-Genealogical tree(拓扑排序)
- POJ 2367 Genealogical tree (拓扑排序)
- Genealogical tree POJ 2367【拓扑排序】
- poj 2367 Genealogical tree(拓扑排序)
- POJ 2367 Genealogical tree(拓扑排序)
- Java并发编程:深入剖析ThreadLocal
- 在C#中使用Google Protocol Buffers
- nodejs 安装没有找到 configure
- POJ 2186 Popular Cows
- 语义化标签
- POJ 2367 Genealogical tree【拓普排序】
- 第一篇博文~
- Java并发编程:同步容器
- MAP
- java开发中JDBC连接数据库
- Hibernate+JPA注解
- 字符串-401 - Palindromes
- 如何根据基类指针来判断这个基类是由那个子类转换而来!
- leetcode.177. Nth Highest Salary