#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int N = ;
int in[N],n,r;
vector<int>ans;
vector<int>edge[N];
priority_queue<int,vector<int>,greater<int> >priq;
int main(){
ios::sync_with_stdio();
cin>>n;
for(int i = ;i <= n;++i){
while(cin>>r){
if(r==)break;
edge[i].push_back(r);in[r]++;
}
}
for(int i = ;i <= n;++i)if(in[i]==)priq.push(i);
while(!priq.empty()){ int p = priq.top();priq.pop();
ans.push_back(p);
for(int j = ;j < edge[p].size();++j){
int y = edge[p][j];in[y]--;
if(!in[y])priq.push(y);
}
}
for(int i = ;i < n;++i){
if(i!=n-)cout<<ans[i]<<" ";
else cout<<ans[i]<<endl;
}
return ;
}

没什么好说的?自己练习拓排概念用的,目前理解的便是,找到入度为0的点加入队列,如果有字典序或者什么要求则用优先队列自定义排序写,然后删除加入队列的点所连接的边(减去其

指向的点的入度)然后当出现入度为0的点时再次加入队列,直到结束。如果最后队列中的点与所有点数目不一致,就说明有环或者别的,不能使用拓排

POJ2367(拓扑排序裸题的更多相关文章

  1. POJ2367 拓扑排序 裸题 板子题

    http://poj.org/problem?id=2367 队列版 #include <stdio.h> #include <math.h> #include <str ...

  2. UVa 10305 - Ordering Tasks (拓扑排序裸题)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  3. uva 10305 拓扑排序裸题

    https://vjudge.net/problem/UVA-10305 目前没学dfs做法,用的队列做法,每次找到一个入度为零的点出队后更新其他点,再加入入度为零的点直到查找完毕,这个题目显然一定有 ...

  4. HDU1285(拓扑排序裸题

    ..被多组测试坑了一波 #include<iostream> #include<vector> #include<queue> using namespace st ...

  5. 三维拓扑排序好题hdu3231

    /* 三维拓扑排序 将每个长方体分解成六个面,xyz三维进行操作 每一维上的的所有长方体的面都应该服从拓扑关系,即能够完成拓扑排序=如果两个长方体的关系时相交,那么其对应的三对面只要交叉即可 如 a1 ...

  6. HDU 1285 经典拓扑排序入门题

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. HDU1285-确定比赛名次-拓扑排序板子题

    有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...

  8. HDU 1285 确定比赛名次 拓扑排序模板题

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 #include <cstdio> #include <cstdlib> #inc ...

  9. POJ 2367 Genealogical tree 拓扑排序入门题

    Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8003   Accepted: 5184 ...

随机推荐

  1. Linux进程通信之文件

    父子进程共享打开的文件描述符------使用文件完成进程间通信. /*** fork_share_fd.c ***/ #include <stdio.h> #include <uni ...

  2. HDU 3689 Infinite monkey theorem ——(自动机+DP)

    这题由于是一个单词,其实直接kmp+dp也无妨.建立自动机当然也是可以的.设dp[i][j]表示匹配到第i个字母的时候,在单词中处于第j个位置的概率,因此最终的答案是dp[0~m][len],m是输入 ...

  3. Difference Between static and default methods in interface

    I was learning through interfaces when I noticed that you can now define static and default methods ...

  4. find命令计算代码行数

    [anonymous@localhost ~/lvs/ipvsadm- -regex '.*Makefile.*' -o -regex '.*\.[ch]' -exec cat {} \; | wc ...

  5. 第七章 python基础之函数,递归,内置函数

    五 局部变量和全局变量 name='cyj' #在程序的一开始定义的变量称为全局变量. def change_name(): global name #global 定义修改全局变量. name=&q ...

  6. Zookeeper系列(十四)Zookeeper的数据与存储

    作者:leesf    掌控之中,才会成功:掌控之外,注定失败. 出处:http://www.cnblogs.com/leesf456/p/6179118.html尊重原创,奇文共欣赏: 一.前言 前 ...

  7. nginx实现负载均衡、缓存功能实战

    nginx实现负载均衡.缓存功能实战 什么是正向代理?应用场景:翻墙 什么是反向代理?例如:haproxy和nginx   Nginx实现反向代理 nginx代理基于是ngx_http_proxy_m ...

  8. postgreSQL计算总数sum if case when

    假设postgreSQL中表名为user,现在需要计算每个用户参加过的次数(is_join字段为null时不算,表中的null并不是字符串''或者字符串'Null' ,而是数据库中的null类型) u ...

  9. Qt 插件学习(一)

    插件是什么 注意:这儿暂时不考虑静态插件(潜意识中总觉得它根本就不算插件). 插件是一个动态库(共享库).动态库是一个独立的文件中的独立模块,可被多个程序访问. 先看动态库的两种用法 1. 程序链接时 ...

  10. HearthBuddy BotManager

    MainWindow private void button_0_Click(object sender, RoutedEventArgs e) { Configuration.Instance.Sa ...