1022. Genealogical Tree
来源:互联网 发布:软件测试全程项目 编辑:程序博客网 时间:2024/05/29 17:21
1022. Genealogical Tree
Time Limit: 1.0 second
Memory Limit: 16 MB
Memory Limit: 16 MB
Background
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.
Problem
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 integers 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
504 5 1 01 05 3 03 0
2 4 5 3 1
拓扑排序
#include <iostream>#include <algorithm>using namespace std;int main(){int n, i, j, k;int a[100][100], b[101];cin>>n;for (i=0; i<n; i++){j = 0;cin>>a[i][j];while (a[i][j])cin>>a[i][++j];}memset(b, 0, 101*sizeof(int));k = 0;while (k < n){for (i=0; i<=n; i++)if (b[i] != 2)b[i] = 0;for (i=0; i<n; i++)if (b[i+1] != 2)for (j=0; a[i][j]; j++)if (b[a[i][j]] == 0)b[a[i][j]] = 1;for (i=1; i<=n; i++)if (!b[i]){cout<<i<<" ";b[i] = 2;k++;}}cout<<endl;}
- URAL 1022. Genealogical tree
- ural 1022. Genealogical Tree
- 1022. Genealogical Tree
- URAL 1022. Genealogical Tree
- Genealogical tree
- Genealogical tree
- Genealogical Tree
- Genealogical tree
- Timus 1022. Genealogical tree 拓补排序
- ural 1022. Genealogical Tree 拓扑排序
- ural 1022. Genealogical Tree 拓扑排序
- ural 1022. Genealogical Tree Topological sort
- ural 1022. Genealogical Tree 拓扑排序
- POJ2367 Genealogical tree
- pku2367 Genealogical tree
- ural 1022 Genealogical Tree
- poj 2367 Genealogical tree
- poj 2367 Genealogical tree
- 连接池有那几种 分别有什么区别
- windows和linux获取文件夹内容的一种方法
- 面向对象——接口(一)
- 修改Windows下的Memcached下的服务端口
- CSS的未来:一些试验性CSS属性
- 1022. Genealogical Tree
- sysbench-一个系统及mysql性能测试的好工具!
- 标准C语言库 Glibc 2.15
- Android重要组件使用方法汇总
- UESTC :吴神的战役
- 深入android界面构造
- Android中的异步IO-Select模型
- 既然决定了要走的路,就是跪着也要走完!!!
- VC开发平台,MFC中添加C文件,提示错误及解决办法