hdu1285 确定比赛名次(拓扑排序)
确定比赛名次
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 51 Accepted Submission(s) : 32
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
其他说明:符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前;输入数据保证是正确的,即输入数据确保一定能有一个符合要求的排名。
Sample Input
4 3
1 2
2 3
4 3
Sample Output
1 2 4 3
#include <iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int i,n,m;
int a[],cnt[];
struct cmp
{
bool operator()(int a,int b)
{
return a>b;
}
};
vector<int> s[];
void toposort()
{
priority_queue<int,vector<int>,cmp> Q;
int l=;
for(int i=;i<=n;i++)
if (cnt[i]==) Q.push(i);
while(!Q.empty())
{
int u=Q.top();
Q.pop();
a[++l]=u;
for(int i=;i<s[u].size();i++)
{
cnt[s[u][i]]--;
if (cnt[s[u][i]]==) Q.push(s[u][i]);
}
}
return;
}
int main()
{
memset(cnt,,sizeof(cnt));
while(~scanf("%d%d",&n,&m))
{
for(i=;i<=n;i++) s[i].clear();
for(i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
s[x].push_back(y);
cnt[y]++;
}
toposort();
for(i=;i<n;i++)printf("%d ",a[i]);
printf("%d\n",a[n]);
}
return ;
}
hdu1285 确定比赛名次(拓扑排序)的更多相关文章
- hdu1285 确定比赛名次(拓扑排序)
		
有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...
 - hdu1285 确定比赛名次(拓扑排序多种方法)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 Problem Description 有N个比赛队(1<=N<=500),编号依次 ...
 - hdu1285确定比赛名次(拓扑排序+优先队列)
		
传送门 第一道拓扑排序题 每次删除入度为0的点,并输出 这题要求队名小的排前面,所以要用到重载的优先队列 #include<bits/stdc++.h> using namespace s ...
 - 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进行比赛,比赛 ...
 - HDOJ 1285 确定比赛名次(拓扑排序)
		
Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...
 - HDU1285-确定比赛名次-拓扑排序板子题
		
有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...
 - HDU 1285 确定比赛名次   拓扑排序模板题
		
http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include <cstdio> #include <cstdlib> #inc ...
 - 图论--拓扑排序--HDU-1285确定比赛名次
		
Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委 ...
 
随机推荐
- Cross Product
			
Cross Product These are two vectors: They can be multiplied using the "Cross Product" (als ...
 - Java Tcp文件传输---转载
			
/** 客户端 1.服务端点 2.读取客户端已有的文件数据 3.通过socket输出流发给服务端 4.读取服务端反馈信息 5.关闭 **/ import java.io.*; import java. ...
 - 【TestDirector】常见问题分析
			
1.IE7无法访问TD 问题原因:兼容性问题 解决方法:步骤一.以系统管理员身份登陆TD: 步骤二.找到TD服务器中TDBIN目录(缺省情况下是C:\Inetpub\TDBIN目录),用编辑器打开st ...
 - python读取bin文件并下发串口
			
# coding:utf-8import time, serialfrom struct import *import binascii file = open('E:\\1.bin', 'rb')i ...
 - mysql高级查询
			
高级查询: 1.连接查询 select * from Info,Nation #得出的结果称为笛卡尔积select * from Info,Nation where Info.Nation = Nat ...
 - 从0开始学习blockchain
			
http://www.8btc.com/build-your-own-blockchain
 - 运行指定路径下的exe
			
public void StartProcess(string name) { string exeFileName = "DataControl.exe"; string sta ...
 - Compile Time Assertion..
			
The most seen assertion are during runtime, but this one is at compile time, to give the error more ...
 - android:layout_weight属性的使用方法总结
			
原创文章,转载请注明出处http://www.cnblogs.com/baipengzhan/p/6282826.html android:layout_weight属性可以和其他属性配合使用,产生多 ...
 - python 输出重定向
			
使print既打印到终端,又写入文件 class Tee(object): def __init__(self,*files): self.files = files def write(self,o ...