hdu 1285 确定比赛名次(给一个拓扑有序图要求输出拓扑有序序列)
来源:互联网 发布:madness淘宝店哪个真 编辑:程序博客网 时间:2024/06/04 23:23
1.如果有向图无回路,那么该图拓扑有序。
2代码:
#include<cstdio>#include<cstring>using namespace std;int mat[505][505];int n,m;int in[505];void topological_sort(){ int cnt=n; while(cnt--) { int i; for(i=1; i<=n; i++) { if(in[i]==0) break; } printf("%d",i); in[i]=-1; if(cnt) { printf(" "); } for(int j=1; j<=n; j++) { in[j]-=(mat[i][j]); } } printf("\n");}int main(){ while(scanf("%d%d",&n,&m)==2) { memset(mat,0,sizeof(mat)); memset(in,0,sizeof(in)); for(int i=0; i<m; i++) { int a,b; scanf("%d%d",&a,&b); mat[a][b]++; in[b]++; } topological_sort(); } return 0;}
0 0
- hdu 1285 确定比赛名次(给一个拓扑有序图要求输出拓扑有序序列)
- 【HDU】1285 - 确定比赛名次(拓扑)
- HDU 1285 拓扑排序 确定比赛名次
- HDU 1285 拓扑排序-- 确定比赛名次
- hdu 1285 确定比赛名次(拓扑排序)
- HDU 1285 确定比赛名次 拓扑排序
- hdu 1285 确定比赛名次(拓扑)
- 【HDU】1285 确定比赛名次 拓扑排序
- HDU【1285】确定比赛名次---拓扑排序
- HDU-1285--确定比赛名次 (拓扑排序)
- 【拓扑排序】HDU 1285--- 确定比赛名次
- hdu 1285 确定比赛名次 拓扑排序
- hdu 1285 确定比赛名次 拓扑排序
- hdu 1285 确定比赛名次 拓扑排序
- HDU 1285 确定比赛名次 拓扑排序
- HDU 1285 - 确定比赛名次 <拓扑排序>
- 拓扑排序:hdu 1285 确定比赛名次
- 拓扑排序 HDU 1285 确定比赛名次
- Tomcat中JVM内存溢出及合理配置
- 控件——时间与日期
- react-native试玩(1)
- Android 图片缩放,手势,事件
- hdu 5328 Problem Killer
- hdu 1285 确定比赛名次(给一个拓扑有序图要求输出拓扑有序序列)
- hihoCoder_#1066_无间道之并查集
- nefu989考试安排
- 常用STL总结
- phpize报错:Cannot find config.m4
- 曾经知乎里的提问
- powerbuilder 与sqlite3数据库
- Windows Azure 故障转移模式及高可用个模式探讨!
- nefu993计数问题