HDU 1285 确定比赛名次 拓扑排序
2015-12-17 16:41
357 查看
思路:就是每次找一个入度为0的点。然后把这个点删掉,并将这个点连着的其他点的入度减1。
http://acm.hdu.edu.cn/showproblem.php?pid=1285/********************************************* Problem : HDU 1258 Author : NMfloat InkTime (c) NM . All Rights Reserved . ********************************************/ #include <map> #include <set> #include <queue> #include <cmath> #include <ctime> #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #define rep(i,a,b) for(int i = (a) ; i <= (b) ; i ++) #define rrep(i,a,b) for(int i = (b) ; i >= (a) ; i --) #define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next) #define cls(a,x) memset(a,x,sizeof(a)) #define eps 1e-8 using namespace std; const int MOD = 1e9+7; const int INF = 0x3f3f3f3f; const int MAXN = 505; const int MAXE = 50005; typedef long long LL; typedef unsigned long long ULL; int T,n,m,k; int fx[] = {0,1,-1,0,0}; int fy[] = {0,0,0,-1,1}; int ru[505]; struct Edge { //记录边 int to; Edge * next; }E[MAXE],*EE; struct Gragh { //记录图的结点 Edge * first; }G[MAXN]; void addedge(int u,int v) { //加边,双向边 EE->to = v ; EE -> next = G[u].first ; G[u].first = EE ++; //EE->to = u ; EE -> next = G[v].first ; G[v].first = EE ++; } int ans[505]; void init() { EE = E; cls(G,0); cls(ru,0); } void input() { int u,v; rep(i,1,m) { scanf("%d %d",&u,&v); addedge(u,v); ru[v] ++; } } void JIAN(int u) { repE(p,u) { int v = p -> to; ru[v] --; } } void solve() { rep(i,1,n) rep(j,1,n) { if(ru[j] == 0) { ru[j] = -1; ans[i] = j; JIAN(j); break; } } rep(i,1,n) { printf("%d",ans[i]); if(i == n) printf("\n"); else printf(" "); } } int main(void) { //freopen("a.in","r",stdin); //scanf("%d",&T); while(T--) { while(~scanf("%d %d",&n,&m)) { //while(~scanf("%d",&n)) { init(); input(); solve(); } return 0; }
相关文章推荐
- Genetic Algorithm遗传算法学习
- LCA最近公共祖先算法
- Leetcode197: Best Time to Buy and Sell Stock with Cooldown
- 介绍几款Python解释器
- 发布程序后显示:未能创建类型
- [转!]jQuey中的return false作用是什么
- uC/OS-II学习笔记—空闲链表和就绪链表
- HTML中DIV与SPAN的区别
- 黑马程序员--浅谈Overload和Override的区别
- 快速掌握WordPress中加载JavaScript脚本的方法
- Trie树算法
- 使用UstraISO制作ISO文件教程
- array_name和&array_name的异同
- ld: library not found for -lPods- -AFNetworking
- ReviewBoard 的安装和使用(三)—— Git仓库的配置
- oracle 常用表操作
- asp.net 验证控件
- 国内外交互体验很好的十款验证码
- hive命令的3种调用方式
- Java-Logger简单使用