PAT 1004

来源:互联网 发布:编程语言 使用范围 编辑:程序博客网 时间:2024/06/07 06:46
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>#include<queue>#include<stack>#include<cmath>using namespace std;const int maxn=100010;struct Node{int weight;vector<int>child;}node[maxn];int n;int p;int ans=0;int _time[maxn]={0};int maxdepth=0;void dfs(int index,int depth){if(node[index].child.size()==0){_time[depth]++;if(depth>maxdepth){maxdepth=depth;}return;}for(int i=0;i<node[index].child.size();i++){int child=node[index].child[i];dfs(child,depth+1);}}int main(){scanf("%d%d",&n,&p);int id,k,child;for(int i=0;i<p;i++){scanf("%d%d",&id,&k);for(int j=0;j<k;j++){scanf("%d",&child);node[id].child.push_back(child);}}dfs(1,1);for(int i=1;i<maxdepth;i++){printf("%d ",_time[i]);}printf("%d",_time[maxdepth]);system("pause");return 0;}

0 0
原创粉丝点击