Genealogical tree
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4420   Accepted: 2933   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

Source

题解: 知道一个数n, 然后n行,编号1到n, 每行输入几个数,该行的编号排在这几个数前面,输出一种符合要求的编号名次排序。

此题中的就看测试数据

0

4 5 1 0

1 0

5 3 0

3 0

可知1后面什么也没有,2后面有4,5,1;3后面有1;4后面有5,3;5后面有3;

即上图

#include<cstdio>
#include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;
#define N 101
int cnt,vis[N],du[N],e[N][N],a[N],n,m;
stack<int>s;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
int x;
while(scanf("%d",&x)==){
if(!x) break;
e[i][x]=;
du[x]++;
}
}
for(int i=;i<=n;i++){
if(!du[i]){
s.push(i);
vis[i]=;
a[++cnt]=i;
}
}
while(!s.empty()){
int p=s.top();
s.pop();
for(int i=;i<=n;i++){
if(e[p][i]){
du[i]--;
}
}
for(int i=;i<=n;i++){
if(!du[i]&&!vis[i]){
s.push(i);
vis[i]=;
a[++cnt]=i;
}
}
}
for(int i=;i<=cnt;i++){
printf("%d ",a[i]);
}
return ;
}
 

poj2367的更多相关文章

  1. [poj2367]Genealogical tree_拓扑排序

    Genealogical tree poj-2367 题目大意:给你一个n个点关系网,求任意一个满足这个关系网的序列,使得前者是后者的上级. 注释:1<=n<=100. 想法:刚刚学习to ...

  2. poj2367 拓扑序

    题意:有一些人他们关系非常复杂,一个人可能有很多后代,现在要制定一种顺序,按照前辈在后代前排列就行 拓扑序裸题,直接建边拓扑排序一下就行了. #include<stdio.h> #incl ...

  3. POJ2367 Genealogical tree (拓扑排序)

    裸拓扑排序. 拓扑排序 用一个队列实现,先把入度为0的点放入队列.然后考虑不断在图中删除队列中的点,每次删除一个点会产生一些新的入度为0的点.把这些点插入队列. 注意:有向无环图 g[] : g[i] ...

  4. POJ2367【拓扑排序】

    很裸的拓扑排序~ //#include <bits/stdc++.h> #include<iostream> #include<string.h> #include ...

  5. 纯拓扑排序一搞poj2367

    /* author: keyboarder time : 2016-05-18 12:21:26 */ #include<cstdio> #include<string.h> ...

  6. POJ2367 拓扑排序 裸题 板子题

    http://poj.org/problem?id=2367 队列版 #include <stdio.h> #include <math.h> #include <str ...

  7. poj2367 Genealogical tree

    思路: 拓扑排序,这里是用染色的dfs实现的.在有环的情况下可以判断出来,没有环的情况下输出拓扑排序序列. 实现: #include <vector> #include <cstri ...

  8. POJ2367(拓扑排序裸题

    #include<iostream> #include<vector> #include<queue> using namespace std; typedef l ...

  9. 拓扑排序 POJ2367Genealogical tree[topo-sort]

    ---恢复内容开始--- Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4875   A ...

随机推荐

  1. scala测试框架:scalatest

    api文档:http://tool.oschina.net/apidocs/apidoc?api=scalatest-1.7.2 trait Assertions:http://tool.oschin ...

  2. C++中的类所占内存空间+继承中的成员访问控制

    C++学习之继承中的成员访问控制 C++中的类所占内存空间总结

  3. CSU - 1542 Flipping Parentheses (线段树)

    CSU - 1542 Flipping Parentheses Time Limit: 5000MS   Memory Limit: 262144KB   64bit IO Format: %lld ...

  4. 2017.6.26 接口测试工具postman使用总结

    参考来自: http://www.cnblogs.com/sunshine-sky66/p/6369963.html http://www.cnplugins.com/tool/specify-pos ...

  5. css 背景 平移 动画

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  6. 我攻克了oom

    BitmapFactory.Options options=new BitmapFactory.Options();     options.inJustDecodeBounds = false;   ...

  7. [linux]netstat命令详解-显示linux中各种网络相关信息

    1.功能与说明 netstat 用于显示linux中各种网络相关信息.如网络链接 路由表  接口状态链接 多播成员等等. 2.参数含义介绍 -a (all)显示所有选项,默认不显示LISTEN相关-t ...

  8. js中的四舍五入函数

    刚学到这部分时,感觉特别简单.可最近写个ajax分页时,忽然忘记应该怎么使用哪种函数来计算总的页数...哎,好记星不如烂笔头啊,还是老老实实的写下来吧.随时查看. 1.Math.ceil(x):对x向 ...

  9. CentOS6安装和卸载docker

    系统版本 [root@bogon yum.repos.d]# uname -a Linux bogon 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 ...

  10. UVA 11354 - Bond (最小生成树 + 树链剖分)

    题目链接~~> 做题感悟:这题開始看到时感觉不是树不优点理,一想能够用 Kruskal 处理成树 ,然后就好攻克了. 解题思路: 先用 Kruskal 处理出最小生成树.然后用树链剖分 + 线段 ...