【HDOJ】1285 确定比赛名次
2014-04-13 17:38
288 查看
拓扑排序,居然要考虑重边,使用STL实现。
#include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; #define MAXNUM 505 char map[MAXNUM][MAXNUM]; int node[MAXNUM]; priority_queue<int, vector<int>, greater<int> > teams; int main() { int n, m, a, b; int i, j; while (scanf("%d%d", &n, &m) != EOF) { memset(node, 0, sizeof(node)); memset(map, 0, sizeof(map)); for (i=0; i<m; ++i) { scanf("%d %d", &a, &b); if (map[a][b] == 0) node[b]++; map[a][b] = 1; } for (i=1; i<=n; ++i) if (node[i] == 0) teams.push(i); j = 0; while ( !teams.empty() ) { a = teams.top(); teams.pop(); if (j == 0) { printf("%d", a); j = 1; } else printf(" %d", a); for (i=1; i<=n; ++i) if (map[a][i]) { node[i]--; if (node[i] == 0) teams.push(i); } } printf("\n"); } return 0; }
相关文章推荐
- ECJTU&&JXUST 13级新生友谊赛 题解
- Python入门教程-04 再论函数
- AngulatJS factory 使用Module(模块)组织依赖关系
- 关闭android系统自动更新
- 国内2大Git代码托管网站
- PropertySheet最简化例子
- 带着目标,努力前进!
- Java 将字节数组转化为16进制的多种方案
- Java 将字节数组转化为16进制的多种方案
- java程序流程控制之循环
- Java 将字节数组转化为16进制的多种方案
- 每天一句 linux命令
- Java 将字节数组转化为16进制的多种方案
- (转)[图]美国面试最难的25家公司 谷歌第8微软第16
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)
- ArcGIS Engine 桌面工具参考技巧
- ad test
- django中form的CSS样式
- 学校就业管理系统需求分析笔记
- ACM Sdut 2158 Hello World!(数学题,排序) (山东省ACM第一届省赛C题)