hdoj-1285-确定比赛名次(拓扑排序)
/*
Name:hdoj-1285-确定比赛名次
Copyright:
Author:
Date: 2018/4/11 15:59:18
Description:
标准的拓扑排序模板题,注意要优先小号输出
*/
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1e+;
int du[MAXN], n , m, L[MAXN];
vector<int> g[MAXN];
int topsort() {
memset(du, , sizeof(du));
for (int i=; i<n; i++) {
for (int j=; j<g[i].size(); j++) {
du[g[i][j]]++;
}
}
int tot = ;
priority_queue<int, vector<int>, greater<int>> Q;
for (int i=; i<n; i++) {
if (!du[i]) {
Q.push(i);
}
}
while (!Q.empty()) {
int x = Q.top();
Q.pop();
L[tot++] = x;
for (int j=; j<g[x].size(); j++) {
int t = g[x][j];
du[t]--;
if (!du[t]) {
Q.push(t);
}
}
}
if (tot == n) return ;
return ;
}
int main()
{
// freopen("in.txt", "r", stdin);
while (cin>>n>>m) {
memset(L, , sizeof(L));
memset(g, , sizeof(g));
for (int i=; i<m; i++) {
int a, b;
cin>>a>>b;
a--;
b--;
if (find(g[a].begin(), g[a].end(), b) != g[a].end()) continue;
g[a].push_back(b);
}
if (topsort() == ) {
cout<<L[]+ ;
for (int i=; i<n; i++) {
cout<<" "<<L[i]+;
}
}
cout<<endl;
}
return ;
}
hdoj-1285-确定比赛名次(拓扑排序)的更多相关文章
- HDOJ 1285 确定比赛名次(拓扑排序)
Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...
- HDU.1285 确定比赛名次 (拓扑排序 TopSort)
HDU.1285 确定比赛名次 (拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 只不过这道的额外要求是,输出字典序最小的那组解.那么解决方案就是 ...
- ACM: HDU 1285 确定比赛名次 - 拓扑排序
HDU 1285 确定比赛名次 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- hdu 1285 确定比赛名次 拓扑排序
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛 ...
- HDU 1285 确定比赛名次 拓扑排序模板题
http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include <cstdio> #include <cstdlib> #inc ...
- hdoj 1285 确定比赛名次【拓扑排序】
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdoj 1285 确定比赛名次 【拓扑排序】
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- hdu1285 确定比赛名次(拓扑排序多种方法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 Problem Description 有N个比赛队(1<=N<=500),编号依次 ...
- hdu 1285 确定比赛名次 (拓扑)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- [ACM] hdu 1285 确定比赛 (拓扑排序)
确定比赛 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
随机推荐
- oracle扩容
动态添加表空间: alter tablespace cbs_cos add datafile '/dba/oradata/ORADEVdatafile/cbs_cos02.dbf' size 100m ...
- facebook开源了他们的分布式大数据DB
https://github.com/facebook/presto facebook 3天前开源了他们的 分布式大数据DB Distributed SQL query engine for big ...
- linux驱动的异步通知(kill_fasync,fasync)---- 驱动程序向应用程序发送信号
应用程序 #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include < ...
- node中session存储与销毁,及session的生命周期
1.首先在使用session之前需要先配置session的过期时间等,在入口文件app.js中 app.use(express.session({ cookie: { maxAge: config.g ...
- js实现给一个数组监听
$.when.apply(null, table).done(callback); table=[]是个数组,用上$.when.apply就可以监听完成后执行callback 方法 callback就 ...
- linux下安装eclipse并使用xstart远程使用(centos7)
1 eclipse安装 1)到官网下载eclipse的linux版 http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-deve ...
- Django 组合索引
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join( ...
- Bootstrap3组件--2
目录 1. 分页 2. 标签 3. 徽章 4. 巨幕 5. 页头 6. 缩略图 7. 警告框 8. 进度条 9. 列表组 10. 面板 11.Well 1. 分页 <!doctype html& ...
- 利用paramiko获取上传下载远程服务器的资源信息
# -*- coding: utf-8 -*- import paramikohostname='192.168.76.10'username='root'password='123456'param ...
- 3.Pycharm和navicate的使用
Pycharm的下载 进入到Pycharm官网,进入网页的最下边,下载企业版enterprise(可试用30天),企业版提供了创建项目.run等功能,而免费版没有这些功能 pycharm的使用: 在f ...