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. vuetifyjs简介及其使用

    何为 vuetify 一个vue ui库,提供vue组件供使用.根据 Google Material Design 指南实现(https://material.io/).Vuetify支持SSR(服务 ...

  2. R in action读书笔记(13)第十章 功效分析

    功效分析 功效分析可以帮助在给定置信度的情况下,判断检测到给定效应值时所需的样本量.反过来,它也可以帮助你在给定置信度水平情况下,计算在某样本量内能检测到给定效应值的概率.如果概率低得难以接受,修改或 ...

  3. Win7系统32位和64位的区别

    Win7系统32位和64位的区别已经是一个老话题了,可是还是有很多朋友不明白.这两者到底有什么区别呢?下面本文与大家通俗的介绍下Win7系统32位和64位的区别,其他一些深入的理论讲述,大家可以看看文 ...

  4. JavaScript——responseType

    https://www.cnblogs.com/cdemo/p/5225848.html https://blog.csdn.net/wkyseo/article/details/78232485 异 ...

  5. Fragment中获取Activity的Context (转)

    Fragment中获取Activity的Context时只需要this.getActivity()即可.     而不是许多人说的this.getActivity().getApplicationCo ...

  6. Winform窗体验证登陆

    用户名,密码尽量不要在BLL,UIL判断,尽可能的在储存过程判断,通过返回的值不同,进行判断,这样提高安全性SQL Server储存过程代码: BEGINif(exists ( select User ...

  7. element-ui iview-admin 都是基于vue的ui框架

    element-ui iview-admin 都是基于vue的ui框架

  8. CAD参数绘制半径标注(网页版)

    主要用到函数说明: _DMxDrawX::DrawDimRadial 绘制一个半径标注.详细说明如下: 参数 说明 DOUBLE dCenterX 被标注的曲线的中点X值 DOUBLE dCenter ...

  9. D2. Toy Train

    D2. Toy Train time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  10. maven release插件将一版本发布到仓库中时Return code is: 401, ReasonPhrase:Unauthorized

    需要在maven的setting.xml中配置servers.server节点,其值为nexus的对应的repository的id以及用户名及密码 <servers> <server ...