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. iOS学习4_UITableView的使用

    UITableView相当于Android里面的ListView.但功能却比ListView强大太多. 使用UITableView须要指定数据源和代理. 1.显示全部的行 遵守UITableViewD ...

  2. 对于session序列化跟session的钝化与活化的粗浅理解

    1. API对序列化的解释:类通过实现 java.io.Serializable 接口以启用其序列化功能.未实现此接口的类将无法使其任何状态序列化或反序列化.可序列化类的所有子类型本身都是可序列化的. ...

  3. ASP.NET MVC4网站部署在阿里ECS云服务器(WIndows Server 2012+IIS8环境)

    首先交代一下服务器的环境配置 系统是WIndows Server2012(配置的时候选的是全能环境),服务器是IIS8 由于装了VS2012,所以系统也自动装上了.Net Framework4.5,M ...

  4. requirejs主流程解读

    近期读了下requirejs源代码,那叫一个复杂啊(相对于seajs来说).整理出了逻辑的主要部分的流程图,感兴趣的能够看下.欢迎批评指正~ http://www.gliffy.com/go/publ ...

  5. Android Asynchronous Http Client 中文教程

    本文为译文,原文链接https://loopj.com/android-async-http/ 安卓异步httpclient 概述 这是一个异步的基于回调的Android http客户端,构建于Apa ...

  6. react-native 组件默认属性(defaultProps) 及 属性类型验证(PropTypes)

    1.所有的属性类型 2.代码 import PropTypes from 'prop-types'; type Props = {}; export default class App extends ...

  7. react-native 项目实战 -- 新闻客户端(6) -- 完善ListView头部视图

    1.因为需要定时器,所以我们要cd到当前项目根目录下安装这个类库: $ npm i react-timer-mixin --save 2.Component/ScrollImage.js /** * ...

  8. 【VBA】复制单元格批注

    只复制单元格的批注该怎么操作呢?代码如下: Public Sub 复制单元格批注() Dim range1 As range Dim range2 As range '清除G列 Columns(&qu ...

  9. 应用程序之UIWebView的使用

    UIWebView简介 知识点总结 代码实现 一.UIWebView简介 1.是iOS内置的浏览器控件,可以浏览网页.打开文档等2.能够加载html/htm.pdf.docx.txt等格式的文件3.系 ...

  10. spark入门(helloworld插件)

    1 http://www.cnblogs.com/openfire/archive/2013/04/26/3044722.html 2 在bulid文件夹下,(注意为主目录不是插件下的bulid.xm ...