HDU 1285 确定比赛名次
2012-04-29 10:54
302 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1285
拓扑排序 小心重边
View Code
拓扑排序 小心重边
View Code
#include <cstdio> #include <cstring> using namespace std; const int N=510; int g ,ind ,n; int topo ; bool toposort() { for(int i=1;i<=n;i++) { int u; for(u=1;u<=n;u++) if(ind[u]==0) break; if(u>n) return false; topo[i]=u; ind[u]--; for(int v=1;v<=n;v++) if(g[u][v]) ind[v]--; } return true; } int main() { int m; while(~scanf("%d%d",&n,&m)) { memset(g,0,sizeof(g)); memset(ind,0,sizeof(ind)); for(int i=0;i<m;i++) { int u,v; scanf("%d%d",&u,&v); if(g[u][v]) continue; g[u][v]=1; ind[v]++; } toposort(); for(int i=1;i<n;i++) printf("%d ",topo[i]); printf("%d\n",topo ); } return 0; }
相关文章推荐
- HDU-1285 确定比赛名次
- 确定比赛名次,hdu 1285 最简单的拓扑排序,
- hdu 1285 确定比赛名次 (拓扑排序)
- HDU 1285 确定比赛名次
- HDU 1285 确定比赛名次(拓扑排序)
- HDU 1285 确定比赛名次。
- HDU-1285 确定比赛名次 ---- 拓扑排序
- 拓扑排序 HDU 1285 确定比赛名次
- E - 确定比赛名次 HDU - 1285
- HDU 1285 确定比赛名次 拓扑排序
- 【HDU】1285--确定比赛名次(拓扑&&优先队列)
- HDU-1285--确定比赛名次 (拓扑排序)
- HDU 1285 确定比赛名次 Topsort
- HDU 1285 确定比赛名次(拓扑排序)
- HDU 1285 确定比赛名次
- HDU 1285 确定比赛名次(简单拓扑排序)
- 确定比赛名次 HDU - 1285 (拓扑排序)
- HDU 1285:确定比赛名次 【拓扑排序】
- hdu 1285 确定比赛名次
- 拓扑排序学习小记 HDU 1285 确定比赛名次 + HDU 2647 Reward