pat 1004 Counting Leaves

1.3两个测试点没过,若有知道哪里没过的,烦请告知 

#include<stdio.h>
#include<stdlib.h>
//system("Pause");
#define MAX_LENGTH 105

int childNum[MAX_LENGTH];
int level[MAX_LENGTH];
int count[MAX_LENGTH];
int main()
{
	int n,m,i,k,id;
	int childId,maxLevel = 1;
	scanf("%d%d",&n,&m);
	if(m > 0) {
		level[1] = 1;
		while(m--){
			scanf("%d%d",&id,&k);
			childNum[id] = k;
			while(k--) {
				scanf("%d",&childId);
				level[childId] = level[id] + 1;
				if(maxLevel < level[childId])
					maxLevel = level[childId];
			}
		}
		for(i = 1; i <= n; i++) {
			if(childNum[i] <= 0)
				count[level[i]]++;
		}
		for(i = 1; i < maxLevel; i++) {
			printf("%d ",count[i]);
		}
		printf("%d",count[maxLevel]);
	} else {
		printf("%d", n);
	}
	


	return 0;
}


 

你可能感兴趣的:(pat 1004 Counting Leaves)