poj2367Genealogical tre
来源:互联网 发布:jdk 7u79 windows x64 编辑:程序博客网 时间:2024/05/20 13:17
原题连接:http://poj.org/problem?id=2367
思路:拓扑排序
#include<stdio.h>#include<stdlib.h>typedef struct vert{int num; //结点编号struct vert* next;}G_v;typedef struct node{int InDgree,OutDgree; //出度和入度G_v* next;}G_n;G_n P[101]; //结点int main(void){G_v *tmp;G_v *q;int n,i,a,j,count;scanf("%d",&n);for(i = 0;i <= n;i ++){P[i].next = NULL;P[i].InDgree = P[i].OutDgree = 0;}i = 1;while(i <= n){tmp = P[i].next;while(scanf("%d",&a)&&a != 0){P[i].OutDgree ++;P[a].InDgree ++;q = (G_v*)malloc(sizeof(G_v));q->num = a;q->next = NULL;if(tmp == NULL){P[i].next = q;tmp = P[i].next;}else{tmp->next = q;tmp = tmp->next;}}i ++;}count = 1;for(i = 1;i <= n;i ++){if(P[i].InDgree == 0){if(count++ == n){ printf("%d\n",i); break;}elseprintf("%d ",i);tmp = P[i].next;while(tmp){P[tmp->num].InDgree --;tmp = tmp->next;} P[i].InDgree = 200;i = 0;}}return 0;}
0 0
- poj2367Genealogical tre
- tre
- tre
- tre
- tre
- tre
- tre
- tre
- tre
- tre
- tre
- poj2367Genealogical tree
- poj2367Genealogical tree
- 5tre
- TRE整合
- poj2367Genealogical tree 拓扑排序
- TRE Common Mail
- python扩展tre
- centsOs(Linux) memcache 安装教程
- VMWare虚拟机中安装Redhat linux操作系统图解(1)
- 程序员求职简历要点《经典》
- oracle函数
- Linux vi中文乱码处理
- poj2367Genealogical tre
- Redhat6.5安装MySQL5.6 RPM包
- python 中文乱码解决方法
- JS AJAX
- VMWare虚拟机中安装Redhat linux操作系统图解(2)
- 文章标题
- VC6.0工程转换到VS2010版本的常见问题
- 三大框架面试题
- 【算法设计与分析基础】关灯游戏