现在的位置: 首页 > 综合 > 正文

[Ural1022]Genealogical Tree

2018年04月25日 ⁄ 综合 ⁄ 共 437字 ⁄ 字号 评论关闭

http://acm.timus.ru/problem.aspx?space=1&num=1022

#include<iostream>
#include<cstdio>
using namespace std;
int n,r[101],c[101],a[101][101],ans[101],tot,t;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		while(1){
			scanf("%d",&t);
			if(t==0)break;
			r[t]++;c[i]++;
			a[i][c[i]]=t;
		}
	}
	for(int i=1;i<=n;i++)
		if(!r[i])ans[++tot]=i;
	for(int i=1;i<=n;i++){
		t=ans[tot];tot--;
		printf("%d ",t);
		for(int j=1;j<=c[t];j++){
			r[a[t][j]]--;
			if(!r[a[t][j]])ans[++tot]=a[t][j];
		}
	}
	return 0;
}

抱歉!评论已关闭.