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.java除了在类体和方法体(包括参数)中可以声明变量外,其他位置一定不可以声明变量吗?比如高级别的应用里是不是有例外呢? 3.java源文件中代码的组织方式一 ...

  2. Spring Mvc相关随笔

    web.xml部分 1.欢迎界面 <welcome-file-list> <welcome-file>/views/login.jsp</welcome-file> ...

  3. c语言-依赖倒转

    当一个文件(aa.c文件)依赖于头文件(bb.h)时,如果bb.c编译之后形成的bb.o文件重新编译后,aa.o的文件不需要重新编译 aa.c文件: bb.h文件:对bb.c文件进行声明 bb.c文件 ...

  4. rest_framework基于generics.CreateAPIView创建用户

    最近在写新版的devops3.0,被generics.CreateAPIView创建用户密码序列化的问题折磨的欲仙欲死.反复看源码测试,得出下面的流程,这也是做generics.CreateAPIVi ...

  5. frame方式布局一段文子,设置宽高

    计算一段文字的宽高 /** * 计算一段文字的宽高 * * @param size 这段文字的最大宽高 * @param options NSStringDrawingUsesLineFragment ...

  6. 《哈佛商业评论》2017年第5期:4星。成功CEO具有4种行为特质:果断、激励参与、主动适应、稳扎稳打。股东价值最大化的理念有重大缺陷。

    老牌管理学杂志,每期都值得精度.本期几个比较重要的观点:谦逊的CEO能带来更好的业绩:飞利浦创新过度导致业绩下滑:股东最大化的理念有重大缺陷,后果之一是大宗股票的临时持有者可能干预公司事务,强迫公司采 ...

  7. 迅为I.MX6开发板工业级嵌入式开发平台

    迅为-i.MX6开发板是是基于ARM Cortex™-A9架构的高扩展性多核系列应用处理器, i.MX6系列芯片而且根据应用场合的不同,提供了可供选择的单核.双核和四核产品供客户选择.i.MX6系列的 ...

  8. (转)SpringMVC学习(十一)——SpringMVC实现Resultful服务

    http://blog.csdn.net/yerenyuan_pku/article/details/72514034 Restful就是一个资源定位及资源操作的风格,不是标准也不是协议,只是一种风格 ...

  9. 引用类型 (Reference Type Matters)、扩展与派发方式

    引用类型 (Reference Type Matters) 引用的类型决定了派发的方式. 这很显而易见, 但也是决定性的差异. 一个比较常见的疑惑, 发生在一个协议拓展和类型拓展同时实现了同一个函数的 ...

  10. Mysql基本操作、C++Mysql简单应用、PythonMysql简单应用

    MySql基本操作 -- 当指定名称的数据库不存在时创建它并且指定使用的字符集和排序方式 CREATE DATABASE IF NOT EXISTS db_name CHARACTER SET UTF ...