sgu 230
来源:互联网 发布:java 图片透明度处理 编辑:程序博客网 时间:2024/05/01 05:44
拓扑排序。
注意看题。。。不是输出拓扑序而是输出点在拓扑序中的位置,
感觉只有我会被这种东西坑。。。
#include<cstdio>#include<cstdlib>#include<ctime>#include<cmath>#include<cstring>#include<map>#include<string>#include<stack>#include<queue>#include<utility>#include<iostream>#include<algorithm>const int maxn = 105, Nya = -1;int n, m;int g[maxn][maxn];int rd[maxn];int ans[maxn];bool loop = false;int main(){#ifndef ONLINE_JUDGE freopen("sgu230.in","r",stdin); freopen("sgu230.out","w",stdout);#endif std::cin >> n >> m; for(int i = 1, u, v; i <= m; i++) std::cin >> u >> v, g[u][v] ++, rd[v]++; for(int i = 1, t; i <= n; i++) { for(t = 1; t <= n; t++) if(rd[t] == 0) break; if(t > n) {loop = true;break;} for(int j = 1; j <= n; j++) if(g[t][j]) rd[j]-= g[t][j]; ans[t] = i, rd[t]--; } if(loop) std::cout << "No solution" << std::endl; else for(int i = 1; i <= n; i++) std::cout << ans[i] << ' ';#ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0;}
0 0
- sgu 230
- SGU 230 拓扑排序
- sgu-230 Weighings
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- sgu 120
- 【Maven】Eclipse下Maven工程多模块继承和聚合创建
- Uva - 11054 - Wine trading in Gergovia
- 数据库:第16周作业
- URAL 1120. Sum of Sequential Numbers (数学)
- 【韩顺平jsp教程笔记一】MySql下关于分页时取出前几条记录方法(不同于SqlServer)
- sgu 230
- Android开发中执行方法中含有监听时的处理
- 另外一篇关于Linux库的文章(静态库,动态库)
- HDU 2940 Hex Factorial (简单高精度)
- OJ输出日期时间--友元类
- 操作系统之进程同步
- Struts2(六)手工编码方式进行输入校验
- POJ 1260 && HDU 1300 Pearls(dp)
- leetcode Longest Valid Parentheses