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. 输入法不能使用ctrl+shift进行切换的问题

    第一种情况就是,你的输入法只有一种(而且这种输入法并不是“中文(简体) 微软拼音输入法”). 如果是只有一种输入法的话,是无法进行切换的,如果你是想要把输入法切换到无输入法状态,那么你可以通过设置任务 ...

  2. DELLR720 独立显卡DVI转VGA问题

    第一种情况:DELLR720默认不接独立显卡,直接用板载VGA输出,不需要调system blos 第二种情况:DELLR720接独立显卡,需要DVI输出,需要更改系统blos system blos ...

  3. ajty

    ] .Tag //; ].Columns["NodeID"].ColumnName ; ].Tag)["NodeID"]; //(DataRow)row[&qu ...

  4. 用Fiddler或Charles进行mock数据搭建测试环境

    转载:http://blog.csdn.net/qqYJ5/article/details/62216582 应用场景:服务器数据不符合测试条件或者服务器未开发完成时,我们可以通过在本地创建数据来达到 ...

  5. 原来,多年以来,我一直是个curl/CRUD程序员

    curl,就是create,update,remove,list的首字母简写.说是CRUD似乎更流行些,不过无所谓,知道是一个意思就好. curl程序员,就是增改删查程序员,中文说增删改查更加顺口. ...

  6. Angular 学习笔记——filter

    <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...

  7. Time.fixedDeltaTime 固定增量时间

    static var fixedDeltaTime : float Description描述 The interval in seconds at which physics and other f ...

  8. c语言用rand() 函数,实现random(int m)

    函数rand()是真正的随机数生成器.而srand()会设置供rand()使用的随机数种子. 假设你在第一次调用rand()之前没有调用srand(),那么系统会为你自己主动调用srand(). 注意 ...

  9. mongo: 改

    语法:db.CollectionName.upadte(查询表达式,新值,选项); 查询表达式:定位哪些列是要被修改的列(即使查询表达式能命中多行,默认也只改一行,如果想改多行,可以用multi选项, ...

  10. spring 国际化-i18n

    i18n(其 来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版 物,软件,硬件等)无需做大 ...