Genealogical tree. 瀹惰氨鏍? Time Limit: 1 second Memory Limit: 16M
Background 澶ф剰錛氱伀鏄熶漢鐨勭鏃忓叧緋繪瘮杈冩販涔便傚畻鏃忕鐞嗗鍛樹細榪涜寮浼氬彂璦絳夋椿鍔ㄦ椂錛屽張鎯抽伒瀹堝厛闀胯緢錛屽悗鏅氳緢鐨勯『搴忋?浜庢槸鏈変笅闈㈢殑闂錛?
Problem 緙栧啓涓涓▼搴忓緇欏畾鐨勪漢鍛橈紝鍐沖畾涓涓厛鍚庨『搴忥紝 榪欎釜欏哄簭蹇呴』閬靛畧鍏堥暱杈堬紝鍚庢櫄杈堢殑鍘熷垯銆?
Input 棣栬涓篘錛?1 <= N <= 100 ,N涓烘諱漢鏁般傛牴鎹櫨騫翠紶緇燂紝緇欎漢鍛樼敤鑷劧鏁扮紪鍙蜂負1鑷砃銆備互涓嬬殑N琛岋紝絎琁琛屼負絎琁涓漢鐨勫瓙瀛欏垪琛紝瀛愬瓩鐨勯『搴忔槸浠繪剰鐨勶紝鐢ㄧ┖鏍奸殧寮錛屼笖浠?涓虹粨鏉熴傚瓙瀛欏垪琛ㄥ彲浠ユ槸絀虹殑銆?
Output 鍦ㄤ竴琛屽唴杈撳嚭鍙戣█鐨勯『搴忋?濡傛湁澶氫釜欏哄簭婊¤凍鏉′歡錛屽垯杈撳嚭浠諱竴涓傝嚦灝戜細鏈変竴涓弧瓚崇殑欏哄簭鐨勩?
Sample Input
5 0 4 5 1 0 1 0 5 3 0 3 0
Sample Output
2 4 5 3 1
/* URAL 1022 Genealogical tree
* 900803 09:04:18 21 Aug 2005 RoBa 1022 C++ Accepted 0.001 190 KB
* 鎷撴墤鎺掑簭
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int MAX = 101;
int map[MAX][MAX],inde[MAX],taken[MAX];
int main()
{
int i,n,tmp,j;
while (scanf("%d",&n)!=EOF)
{
memset(map,0,sizeof(map));
memset(inde,0,sizeof(inde));
for (i = 1 ; i <= n ; i++)
while (scanf("%d",&tmp),tmp)
{
map[i][tmp] = 1;
++inde[tmp];
}
while (1)
{
for (i = 1 ; i <= n ; i++)
if (inde[i] == 0 && taken[i] == 0) break;
if (i > n) break;
for (j = 1 ; j <= n ; j++)
if (map[i][j])
{
map[i][j] = 0;
--inde[j];
}
taken[i] = 1;
printf("%d ",i);
}
printf("\n");
}
return 0;
}

]]>