Genealogical tree
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6025   Accepted: 3969   Special Judge

Description

The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where they want. They gather together in different groups, so that a Martian can have one parent as well as ten. Nobody will be surprised by a hundred of children. Martians have got used to this and their style of life seems to them natural. 
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

The first line of the standard input contains an only number N, 1 <= N <= 100 — a number of members of the Martian Planetary Council. According to the centuries-old tradition members of the Council are enumerated with the natural numbers from 1 up to N. Further, there are exactly N lines, moreover, the I-th line contains a list of I-th member's children. The list of children is a sequence of serial numbers of children in a arbitrary order separated by spaces. The list of children may be empty. The list (even if it is empty) ends with 0.

Output

The standard output should contain in its only line a sequence of speakers' numbers, separated by spaces. If several sequences satisfy the conditions of the problem, you are to write to the standard output any of them. At least one such sequence always exists.

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的更多相关文章

  1. POJ 2367:Genealogical tree(拓扑排序模板)

    Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7285   Accepted: 4704 ...

  2. POJ 2367:Genealogical tree(拓扑排序)

    Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2738 Accepted: 1838 Spe ...

  3. poj 2367 Genealogical tree

    题目连接 http://poj.org/problem?id=2367 Genealogical tree Description The system of Martians' blood rela ...

  4. poj 2367 Genealogical tree【拓扑排序输出可行解】

    Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3674   Accepted: 2445 ...

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

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

  6. POJ 2367 Genealogical tree【拓扑排序/记录路径】

    Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7101 Accepted: 4585 Spe ...

  7. POJ 2367 topological_sort

    Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2920 Accepted: 1962 Spe ...

  8. timus 1022 Genealogical Tree(拓扑排序)

    Genealogical Tree Time limit: 1.0 secondMemory limit: 64 MB Background The system of Martians’ blood ...

  9. Genealogical tree(拓扑结构+邻接表+优先队列)

    Genealogical tree Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) ...

随机推荐

  1. AJPFX关于多态中的动态绑定和静态绑定的总结

    在多态中:成员变量和静态方法编译和运行都看左边:成员方法编译看左边,运行看右边,这是为什么:在Java中存在两种绑定方式,一种为静态绑定,又称作早期绑定.另一种就是动态绑定,亦称为后期绑定1.静态绑定 ...

  2. Jboss服务器使用

    一.作者前言 早上坐地铁的时候,阅览about JAVA.了解到一个程序猿,对于服务器的使用,最起码的熟悉那么几种,例如tomcat,jboss,weblogic,websphere,还有Nginx. ...

  3. vue全局loading组件

    本组件作用在页面加载完成前进行loader提示,提升用户体验,只需要在app.vue中引用一次,整个项目中路由切换时就可以自动进行提示(vuex版): 1. 添加vuex值和方法: import Vu ...

  4. 读取.properties配置信息

    package com.ctcti.webcallcenter.utils; import java.io.FileInputStream;import java.io.FileNotFoundExc ...

  5. 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom

    代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<alg ...

  6. webstorm快捷键大全-webstorm常用快捷键

    默认配置下的常用快捷键,提高代码编写效率,离不开快捷键的使用,Webstorm拥有丰富的代码快速编辑功能,你可以自由配置功能快捷键. Webstorm预置了其他编辑器的快捷键配置,可以点击 查找/代替 ...

  7. iTOP4418开发板7寸屏幕Android系统下横竖屏设置

    Android系统屏幕旋转设置 平台: iTOP4418开发板+7寸屏幕 1. Androd4.4源码可以编译成手机模式和平板模式,讯为iTop4418 开发平台的Android系统默认编译为平板模式 ...

  8. Swift 命名空间形式扩展的实现

    Swift 的 extension 机制很强大,不仅可以针对自定义的类型,还能作用于系统库的类型,甚至基础类型比如 Int.当在对系统库做 extension 的时候,就会涉及到一个命名冲突的问题.O ...

  9. 使用nsight调试caffe

    首先你需要下载caffe源码,然后先编译好,注意一定要将Makefile.config里的DEBUG := 1注释掉 可以看到注释掉debug后编译会生成的.build_debug目录,调试过程中需要 ...

  10. 只允许特定IP访问本网站的前端写法

    在开发的过程中,有时会遇到只允许特定的几个IP访问.今天来记录一下前端的写法. 首先,引入 <script src="http://pv.sohu.com/cityjson?ie=ut ...