HDU1285(拓扑排序+优先队列)
来源:互联网 发布:东南大学软件测试专业 编辑:程序博客网 时间:2024/06/09 15:26
坑点:重边情况下入度不++,因为即使比赛排名重复出现对节点入度也是没有影响的
#include <iostream>#include <cstdio>#include <vector>#include <queue>#include <cstring>using namespace std;const int MAX_N = 505;vector<int> ans;priority_queue<int, vector<int>, greater<int> > q;int indegree[MAX_N];int n, m;int map[MAX_N][MAX_N];void InitTop(){for (int i = 1; i <= n; i++)if (indegree[i] == 0)q.push(i);}void TopSort(){int temp;int c = 1;while(!q.empty()){temp = q.top();q.pop();if (c != n)printf("%d ", temp), c++;elseprintf("%d\n", temp);for (int i = 1; i <= n; i++){if (map[temp][i]){indegree[i]--;if(indegree[i] == 0)q.push(i);}}}}int main(){while(~scanf("%d %d", &n, &m)){memset(map, 0, sizeof(map));memset(indegree, 0, sizeof(indegree));while(m--){int x, y;scanf("%d %d", &x, &y);if (map[x][y])continue;map[x][y] = 1;indegree[y]++; //重边情况下入度不++}InitTop();TopSort();}return 0;}
0 0
- hdu1285 拓扑排序+优先队列
- HDU1285(拓扑排序+优先队列)
- hdu1285确定比赛名次(拓扑排序+优先队列)
- HDU1285 确定比赛名次【拓扑排序】【优先队列】
- HDU1285基于有向图邻接表的优先队列的拓扑排序
- 拓扑排序+优先队列
- 拓扑排序+优先队列
- hdu1285拓扑排序
- HDU1285 拓扑排序
- HDU1285-拓扑排序
- hdu1285拓扑排序
- hdu1285(拓扑排序)
- hdu1285 拓扑排序
- hdu1285(拓扑排序)
- hdu1285+hdu2467(拓扑排序)
- hdu1285拓扑排序
- hdu1285 简单拓扑排序
- hdu1285(拓扑排序)
- OC对文本的操作
- [Business Intelligence] 1NF, 2NF, 3NF
- ie 7/8/9 placeholder 不显示 解决方案
- 浅析Tomcat之Pipeline和Value
- IntelliJ IDEA 使用心得与常用快捷键
- HDU1285(拓扑排序+优先队列)
- AndroidSDK版本和API版本对于关系
- Singleton模式的实现方式 C#
- JAVA中使用Formatter类进行输出格式的控制
- IQKeyboardManager使用方法
- 基于Web在线考试系统的设计与实现
- 【jQuery】sele1,sele2,seleN选择器
- Reachability
- 鸟巢-一种全新的Native APP开发模式,这篇文章问您解读