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函数返回值

    1.使用returndef functionName ([参数列表]) : [return type] = { function body return [expr] } 2.直接把返回值写在最后: ...

  2. html 打印代码,支持翻页

    ylbtech_html_print html打印代码,支持翻页 <html> <head> <meta name=vs_targetSchema content=&qu ...

  3. 关于宏:container_of和 offsetof以及list_for_each_entry

    1.offsetof(TYPE, MEMBER) #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) offse ...

  4. Android使用TextView,设置onClick属性无效解决的方法

    Android在布局文件里为View提供了onClick属性.用法例如以下: <TextView android:id="@+id/user" android:layout_ ...

  5. Rails 状态码

    Response Class HTTP StatusCode Symbol Informational 100 :continue Success 200 :ok Redirection 300 :m ...

  6. 累加按钮,自加1&&输入两个数字,比较大小

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 倍福TwinCAT(贝福Beckhoff)基础教程 松下绝对值驱动器如何做初始化设置

    安装调试软件PANATERM 6.0,完成之后可以自动检测到连接的设备(如果软件是之前的版本,则可能无法准确识别A5B系列)   点击试运行,伺服关闭,然后会发现伺服开启按钮可用了   测试正反转没有 ...

  8. VM虚拟机 Windows虚拟机中linux鼠标不能动怎么办

    有一次vmware安装red hat linux后,进入x-windows界面,鼠标不能用,百思不得其解,因为自己的安装linux的过程中设置绝对是没有问题的啊,鼠标设置肯定是usb带滑轮,这个肯定没 ...

  9. ssh的一些小操作

    不让对方执行w的时候看到我 ssh -T root@8.8.8.8 bin/sh -i 还有一个技巧:远程登录时防止被记录到knowhosts文件(默认为~/.ssh/knowhosts) ssh - ...

  10. awk、sed、cut、grep

    二.sed [可以理解为 行在线编辑工具] 作用:sed 是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命 ...