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
- pat 1004
- pat 1004
- pat 1004
- PAT 1004
- pat 1004
- PAT 1004
- PAT 1004
- PAT 1004
- PAT 1004
- PAT 1004
- PAT-1004
- pat 1004 Counting Leaves
- pat 1004 counting Leaves
- PAT 1004 Counting Leaves
- PAT basic 1004 : 成绩排名
- 浙江大学pat 1004
- PAT basic practice 1004
- PAT 1004 Counting Leaves
- 历届试题 国王的烦恼 (并查集)
- leetcode 520 python
- java安全架构____RSA加密解密
- 正则表达式
- Android AccessibilityService拦截事件及VR眼镜返回按键捕捉
- PAT 1004
- Codeforces Round #401(Div. 2)E. Hanoi Factory【贪心+栈】
- Mathtype与word字号对照
- 通过反汇编一个简单的C程序,分析汇编代码理解计算机是如何工作的
- OSI七层协议模型和TCP/IP四层模型比较
- [Haskell on HackerEarth] Modify Sequence
- SD卡的使用
- 引用妙用
- JAVA 知识