aboutsummaryrefslogtreecommitdiff
path: root/rcc-legacy/tests/sysy_lvX/065_genealogical_tree.sy
blob: d2fc7ed46fa391e06127a14c2689e48f59c2171f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
int map[10][10];
int indegree[10];
int queue[10];
void topo(int n)
{
	int m=0;
	int t=0;
	int i,j; 
	i=1;
	j=1;
	while(i<=n)
	{
		j=1;
		while(j<=n)
		{
			if(indegree[j]==0)
			{
				
				m=j;
				break;
			}
			j=j+1;
		}
		queue[t]=m;
		t=t+1;
		indegree[m]=-1;
		j=1;
		while(j<=n)
		
		{
			if(map[m][j])
			{
				indegree[j]=indegree[j]-1;
			 } 
			j=j+1;
		}
		i=i+1;
	}
	i=0;
	while(i<n)
	{
		putint(queue[i]); 
		putch(10);
		i=i+1; 
	}
		
}
int main()
{
	int n,p;
	int i=1;
	n=5;

	while(i<=n)
	{
		p=getint();
		while(p!=0)
		{
			map[i][p]=1;
			indegree[p]=indegree[p]+1;
			p=getint();
			
		}
		i=i+1;
	}
	topo(n);
	return 0;
}