《拓扑排序》hdu acm 5.2.4 c++优先队列 邻接表
2015-11-16 01:29
316 查看
#include<iostream> #include<queue> #include<cstdio> #include<cstring> using namespace std; typedef struct v { int vex; v *next; }V; typedef struct h { int indegree; v *next; }H; H team[10010]; V *p; int main() { int i,n,m,a,b,cnt; priority_queue<int,vector<int>,greater<int> > q; while(cin>>n>>m) { memset(team,0,sizeof(team)); for(i=1;i<=n;i++) { } while(m--) { cin>>a>>b; team[b].indegree++; p=new V; p->vex=b; p->next=team[a].next; team[a].next=p; } for(i=1;i<=n;i++) { if(team[i].indegree==0) q.push(i); } cnt=0; while(!q.empty()) { a=q.top(); q.pop(); if(cnt) cout<<' '; cnt++; cout<<a; for(p=team[a].next;p!=0;p=p->next) { b=p->vex; if(--team[b].indegree==0) q.push(b); } } cout<<endl; } return 0; }
相关文章推荐
- C++ 自动创建文件夹
- 顺序栈的操作实现_C语言
- 给亲爱的写的关于爱情的程序--CrazyChao(论IT男的爱情)
- Visual C++语言编程开发详解
- C语言获取网页源代码
- c++记录程序运行时间
- c/c++内存释放知识总结
- C/C++内存泄漏及检测
- C++中获取当前运行路径
- 《more effective C++》条款10 防止构造函数里的资源泄露
- 删除.cpp文件
- UML和模式应用书中C++版 NextGen POS代码
- java中数组和C语言数组的区别
- 一起talk C栗子吧(第六十回:C语言实例--字符串复制)
- C语言中可变参数的应用
- oc语言中的isa指针以及其面向对象语言的设计原理
- C++ && C 带空格的字符串输入
- c++单元测试指南:使用google test
- C语言关键字
- C语言的队列的初始化和先进先出的简洁程序