2015 Multi-University Training Contest 3--1011 Work
2015-07-28 13:16
537 查看
代码:
#include<cstdio> #include<cstring> using namespace std; int n,k; int father[105],son[105]; int dd; void Find(int a) { //int r=son[a]; while(father[a]!=a) { a=father[a]; son[a]+=(dd); //r=son[a]; } //father[r]=a; //return a; } void Union(int a,int b) { father[b]=a; son[a]+=(son[b]+1); dd=son[b]+1; Find(a); } int main() { while(scanf("%d%d",&n,&k)==2) { for(int i=1; i<=n; i++) { father[i]=i; son[i]=0; } for(int i=1; i<n; i++) { int a,b; scanf("%d%d",&a,&b); Union(a,b); } int ans=0; for(int i=1; i<=n; i++) { //printf("%d %d\n",i,son[i]); if(son[i]==k) ans++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- 那些没有root权限的岁月:一分钟解决mutt No mailbox
- UVa 576 - Haiku Review
- Scan IP relocate/failover其它段后不能ping通过
- HDU 1022 Train Problem I 【栈】
- no version information available
- rails之distance_of_time_in_words等显示时间差大概描述的方法
- 【POJ 1151】Air Raid
- Contains Duplicate III
- HTTP请求报文和HTTP响应报文 http://blog.csdn.net/zhangliang_571/article/details/23508953
- HDU 4630 No Pain No Game (线段树离线查询)
- 在rails的console下调用helper方法
- RAID详解[RAID0/RAID1/RAID10/RAID5]
- 对pair元素进行排序
- 用GDB调试程序 http://blog.csdn.net/dadalan/article/details/3758025
- UVA 514 Rails(栈)
- HDU 1789:Doing Homework again
- int main()和void main()的区别
- nexus repair或update index 没反应 速度慢 手动配置nexus index
- ACboy needs your help again!
- [BZOJ1664] [Usaco2006 Open]County Fair Events 参加节日庆祝