BestCoder #1-1 HDU 4857 逆拓扑排序
来源:互联网 发布:开票软件任务是什么 编辑:程序博客网 时间:2024/06/10 04:28
//// main.cpp// HDU 4857 拓扑排序//// Created by 郑喆君 on 8/9/14.// Copyright (c) 2014 itcast. All rights reserved.//#include<cstdio>#include<cstring>#include<iostream>#include<iomanip>#include<queue>#include<cmath>#include<stack>#include<map>#include<vector>#include<set>#include<algorithm>using namespace std;typedef long long LL;const int int_max = 0x07777777;const int int_min = 0x80000000;const int maxn = 31000;struct cmp { bool operator()(int a, int b){ return a < b; }};vector<int> g[maxn];int cnt[maxn];int n,m;int main(int argc, const char * argv[]){ int t; scanf("%d", &t); while(t--){ scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) g[i].clear(); memset(cnt, 0, sizeof(cnt)); for(int i = 0; i < m; i++){ int x,y; scanf("%d %d", &x, &y); g[y].push_back(x); cnt[x]++; } priority_queue<int, vector<int>, cmp> q; for(int i = 1; i <= n; i++) if(!cnt[i]) q.push(i); vector<int> res; while (!q.empty()) { int u = q.top(); q.pop(); res.push_back(u); for(int i = 0; i < g[u].size(); i++) if(--cnt[g[u][i]] == 0) q.push(g[u][i]); } if(n==1){ printf("%d\n", 1); }else{ for(int i = res.size()-1; i > 0; i--) printf("%d ", res[i]); printf("%d\n", res[0]); } } }
0 0
- BestCoder #1-1 HDU 4857 逆拓扑排序
- hdu Bestcoder # 1 逃生 拓扑排序
- hdu 4857/BestCoder Round#1 1001(拓扑排序+逆向建图)
- 20140912 【 拓扑排序 】 bestcoder #1+hdoj 4857 逃生
- hdu4857 & BestCoder Round #1 逃生(拓扑逆排序+优先队列)
- HDU-4857(拓扑排序)
- hdu 4857 拓扑排序
- 【HDU】4857 逃生 逆拓扑排序
- HDU 4857逃生(逆拓扑排序)
- HDU 4857--逃生【拓扑排序 && 反向拓扑】
- HDU 4857 逃生(拓扑排序)
- hdu-4857-逃生-拓扑排序
- hdu 4857(逆序拓扑排序)
- HDU 4857 逃生(拓扑排序)
- hdu-4857 逃生 拓扑排序
- HDU-4857-逃生【拓扑排序】
- hdu 4857 逃生 (拓扑排序)
- BestCoder #1-2 HDU 4858
- itoa()和atoi()函数实现
- Coursera_Stanford密码学公开课 Programming Assignment 4
- 2014 阿里巴巴系统工程师笔试题 北京
- hdu 4924 Football Manager(搜索+剪枝+dp)
- rsync+inotify实现服务器实时备份
- BestCoder #1-1 HDU 4857 逆拓扑排序
- Live555 服务器保存RTSP协议数据为MP4文件
- LAMP---环境搭建
- 【水题-数学】 HDU 1141 Factstone Benchmark
- 二十五:微信公众帐号开发-自定义菜单的view类型(访问网页)
- SQLYog 数据连接配置的迁移
- TCP详解
- 二十六:微信公众帐号开发-应用实例之历史上的今天
- 解析游戏卡顿 影响电脑游戏帧数的因素