博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2367 topological_sort
阅读量:5745 次
发布时间:2019-06-18

本文共 3433 字,大约阅读时间需要 11 分钟。

Genealogical tree
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2920 Accepted: 1962 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
Ural State University Internal Contest October'2000 Junior Session
 
/**********************************************      author   :    Grant Yuan      time     :    2014.7.29      algorithm:    topological_sort      source   :    POJ 2367**********************************************/#include 
#include
#include
#include
#include
#define MAX 101using namespace std;int mat[MAX][MAX],num[MAX];int n,m,ans,sum;int lu[MAX];int main(){ int a,b; while(~scanf("%d",&n)){ memset(mat,0,sizeof(mat)); memset(num,0,sizeof(num)); memset(lu,0,sizeof(lu)); for(int i=1;i<=n;i++) { while(1){ scanf("%d",&a); if(a==0) break; if(mat[i][a]==0) { mat[i][a]=1; num[i]++; } }} int i,p=n; while(1){ for(i=n;i>0;i--) { if(num[i]==0) break; } if(i==0) break; num[i]=-1; lu[p--]=i; for(int j=1;j<=n;j++) { if(mat[j][i]) num[j]--; } } for(int j=1;j<=n;j++) if(j

转载地址:http://flxzx.baihongyu.com/

你可能感兴趣的文章
sqli-labs 下载、安装
查看>>
Linux 网络命令必知必会之 tcpdump,一份完整的抓包指南请查收!
查看>>
RouteReuseStrategy angular路由复用策略详解,深度刨析路由复用策略
查看>>
JavaScript 代码简洁之道
查看>>
Kubernetes API 分析 ( Kube-apiserver )
查看>>
4-学会刷Wi-Fi模块固件(刷AT指令固件)
查看>>
ASP.NET Core 2 学习笔记(五)静态文件
查看>>
Button 使用Command 按钮置灰未更新
查看>>
PostgreSQL控制台以竖行显示
查看>>
CSS-Flex 布局教程:实例篇
查看>>
Java和移动端交互
查看>>
Java SSM 客户管理 商户 管理系统 库存管理 销售报表 项目源码
查看>>
排序优化——如何实现一个通用的、高性能的排序函数
查看>>
IDEA中css文件包红色下划线
查看>>
js中bind、call、apply函数的用法
查看>>
OC高效率52之多用GCD,少用performSelector系列方法
查看>>
sqoop导入关系型数据库-解密Sqoop
查看>>
语音分享应用ios源码项目
查看>>
性能测试结果分析
查看>>
Linux-dns基础知识和BIND的简单配置-1
查看>>