poj——2367 Genealogical tree
Time Limit: 1000MS | Memory Limit: 65536K | |||
Total Submissions: 6025 | Accepted: 3969 | Special Judge |
Description
And in the Planetary Council the confusing genealogical system leads to some embarrassment. There meet the worthiest of Martians, and therefore in order to offend nobody in all of the discussions it is used first to give the floor to the old Martians, than to the younger ones and only than to the most young childless assessors. However, the maintenance of this order really is not a trivial task. Not always Martian knows all of his parents (and there's nothing to tell about his grandparents!). But if by a mistake first speak a grandson and only than his young appearing great-grandfather, this is a real scandal.
Your task is to write a program, which would define once and for all, an order that would guarantee that every member of the Council takes the floor earlier than each of his descendants.
Input
Output
Sample Input
5 0 4 5 1 0 1 0 5 3 0 3 0
Sample Output
2 4 5 3 1 题目重现:
火星人血缘关系的制度令人困惑。实际上,火星人要发芽,想要什么。他们聚集在一起不同的群体,所以一个火星人可以有一个父母以及十个。没有人会惊讶于一百个孩子。火星人习惯了,他们的生活方式似乎是自然的。而在行星委员会,混乱的系谱系统会导致一些尴尬。遇到最有价值的火星人,所以为了在所有的讨论中冒犯任何人,首先要让老火星人,而不是对年轻人,而不是最年轻的无孩子的陪审员。然而,维护这个命令真的不是一件小事。不总是火星人知道他所有的父母(没有什么可以告诉他的祖父母!)。但是,如果一个错误首先说出一个孙子,而不是他的年轻人出现的爷爷,这是一个真正的丑闻。你的任务是编写一个程序,一劳永逸地定义一个可以保证安理会每一位成员比每个后裔早日发言的命令
思路:拓扑排序模板、、、
代码:
#include<queue> #include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> #define N 1010 using namespace std; queue<int>q; int n,m,s,tot,in[N],ans[N],head[N]; struct Edge { int to,next,from; }edge[N]; int add(int x,int y) { tot++; edge[tot].to=y; edge[tot].next=head[x]; head[x]=tot; } int read() { ,f=; char ch=getchar(); ; ch=getchar();} +ch-'; ch=getchar();} return x*f; } int main() { n=read(); ;i<=n;i++) ) { m=read(); ) break; in[m]++;add(i,m); } ;i<=n;i++) ) q.push(i); while(!q.empty()) { m=q.front(),q.pop(); ans[++s]=m; for(int i=head[m];i;i=edge[i].next) { int t=edge[i].to; in[t]--; ) q.push(t); } } ;i<=s;i++) printf("%d ",ans[i]); ; }
poj——2367 Genealogical tree的更多相关文章
- POJ 2367:Genealogical tree(拓扑排序模板)
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7285 Accepted: 4704 ...
- POJ 2367:Genealogical tree(拓扑排序)
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2738 Accepted: 1838 Spe ...
- poj 2367 Genealogical tree
题目连接 http://poj.org/problem?id=2367 Genealogical tree Description The system of Martians' blood rela ...
- poj 2367 Genealogical tree【拓扑排序输出可行解】
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3674 Accepted: 2445 ...
- POJ 2367 Genealogical tree 拓扑排序入门题
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8003 Accepted: 5184 ...
- POJ 2367 Genealogical tree【拓扑排序/记录路径】
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7101 Accepted: 4585 Spe ...
- POJ 2367 topological_sort
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2920 Accepted: 1962 Spe ...
- timus 1022 Genealogical Tree(拓扑排序)
Genealogical Tree Time limit: 1.0 secondMemory limit: 64 MB Background The system of Martians’ blood ...
- Genealogical tree(拓扑结构+邻接表+优先队列)
Genealogical tree Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) ...
随机推荐
- VS2012出现加载失败时的解决办法 win7同样适用
今天更新了WIN8系统补丁,然后就出现了大量的问题,特别是经常用的软件像VS2012 老是加载失败,还说是缺少什么包一类的,弄了好长段时间终于解决了,现在将经验分享下 工具/原料 VS2012+WIN ...
- 关于使用myeclipse搭建tomcat环境运行web项目的方法
这两天准备改同事的一个系统的自适应,然而我没想到的是我竟然在打开这个项目上就遇到了困难,真的是too young too simple,究其根本就是了解的太少了,于是为了我不忘记,用博客的方式把它记录 ...
- 关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(一)-----mapState
一.通过mapState函数的对象参数来赋值: <p>{{ count }}</p> <p>{{ count1 }}</p> <p>{{ c ...
- vue2.0 静态prop和动态prop
动态prop: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...
- python与shell通过微信企业号发送消息
python与shell通过微信企业号发送信息,脚本来源于网络,做好搬运工,哈哈,相应的参考链接放在末位 shell版本: #!/bin/bash # CropID="xxxx" ...
- ie11 突然不能加载外部css 很神奇 头部改为 <!DOCTYPE> <html>
<!DOCTYPE html> <html> 改为 <!DOCTYPE> <html> OK了
- Vue之x-template(1)
今天,我们来讲一个比较有趣的一个功能吧 先来看一段代码示例: <html> <head> <meta charset="utf-8"> < ...
- IO 双引号 输出 输入
#! /usr/bin/perl use strict;use warnings; print "\n---------<STDIN>_store_into_an_array_a ...
- python note of class
reference: https://www.zhihu.com/question/27699413/answer/267906889 摘要: 我们在描述一个真实对象(物体)时包括两个方面:它可以做什 ...
- 如何手写一款KOA的中间件来实现断点续传
本文实现的断点续传只是我对断点续传的一个理解.其中有很多不完善的地方,仅仅是记录了一个我对断点续传一个实现过程.大家应该也会发现我用的都是一些H5的api,老得浏览器不会支持,以及我并未将跨域考虑入内 ...