POJ 2367 Genealogical Tree (topology)

Source: Internet
Author: User

Genealogical tree
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3685 Accepted: 2453 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 has one parent as well as ten. Nobody is surprised by a hundred of children. Martians has 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's used first T o Give 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 was not a trivial task. Not always Martian knows all of the his parents (and there's nothing is about his grandparents!). But the if by a mistake first speak a grandson and only than he young appearing great-grandfather, the 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 T He council takes the floor earlier than each of his descendants.

Input

The first line of the standard input contains a only number n, 1 <= n <= 100-a Number of members of the Martian P Lanetary Council. According to the Centuries-old tradition members of the Council is enumerated with the natural numbers from 1 up to N. Fu Rther, there is 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 is empty. The list (even if it is empty) ends with 0.

Output

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

Sample Input

504 5 1 01 05 3 03 0

Sample Output

2 4 5) 3 1

Source

Ural State University Internal Contest October ' Junior Session



POJ 2367 Genealogical Tree (topology)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.