博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5977 Garden of Eden(点分治求点对路径颜色数为K)
阅读量:5105 次
发布时间:2019-06-13

本文共 2759 字,大约阅读时间需要 9 分钟。

Problem Description
When God made the first man, he put him on a beautiful garden, the Garden of Eden. Here Adam lived with all animals. God gave Adam eternal life. But Adam was lonely in the garden, so God made Eve. When Adam was asleep one night, God took a rib from him and made Eve beside him. God said to them, “here in the Garden, you can do everything, but you cannot eat apples from the tree of knowledge.”
One day, Satan came to the garden. He changed into a snake and went to live in the tree of knowledge. When Eve came near the tree someday, the snake called her. He gave her an apple and persuaded her to eat it. Eve took a bite, and then she took the apple to Adam. And Adam ate it, too. Finally, they were driven out by God and began a hard journey of life.
The above is the story we are familiar with. But we imagine that Satan love knowledge more than doing bad things. In Garden of Eden, the tree of knowledge has n apples, and there are k varieties of apples on the tree. Satan wants to eat all kinds of apple to gets all kinds of knowledge.So he chooses a starting point in the tree,and starts walking along the edges of tree,and finally stops at a point in the tree(starting point and end point may be same).The same point can only be passed once.He wants to know how many different kinds of schemes he can choose to eat all kinds of apple. Two schemes are different when their starting points are different or ending points are different.
 
Input
There are several cases.Process till end of input.
For each case, the first line contains two integers n and k, denoting the number of apples on the tree and number of kinds of apple on the tree respectively.
The second line contains n integers meaning the type of the i-th apple. Types are represented by integers between 1 and k .
Each of the following n-1 lines contains two integers u and v,meaning there is one edge between u and v.1≤n≤50000, 1≤k≤10
 
Output
For each case output your answer on a single line.
 
Sample Input
3 2
1 2 2
1 2
1 3
 
Sample Output
6
题意
给你一棵树,每个点的颜色,问有多少点对满足路径上的所以点颜色数为K。
题解
点分治,把模板的dfsdis改成状态。
代码
1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 7 #define LL long long 8 const int maxn=5e4+5; 9 10 vector
G[maxn]; 11 int n,k,sumk,a[maxn],p[15]; 12 int mx[maxn],size[maxn],vis[maxn],dis[maxn],MIN,num[1050],cnt,root; 13 LL ans; 14 void init() 15 { 16 sumk=(1<
mx[u])mx[u]=size[r]-size[u]; 42 if(mx[u]
=0;j--) 67 if(!(p[i]&j)) 68 num[j]+=num[j|p[i]]; 69 LL ret=0; 70 for(int i=0;i

转载于:https://www.cnblogs.com/taozi1115402474/p/9939633.html

你可能感兴趣的文章
sqoop连接Oracle数据库错误异常
查看>>
伪类与超链接
查看>>
HTML语言的一些元素(二)
查看>>
一段js代码的分析
查看>>
centos 7 redis-4.0.11 主从
查看>>
Java的基本数据类型与转换
查看>>
博弈论 从懵逼到入门 详解
查看>>
永远的动漫,梦想在,就有远方
查看>>
springboot No Identifier specified for entity的解决办法
查看>>
慵懒中长大的人,只会挨生活留下的耳光
查看>>
"远程桌面连接--“发生身份验证错误。要求的函数不受支持
查看>>
【BZOJ1565】 植物大战僵尸
查看>>
视频:"我是设计师"高清完整版Plus拍摄花絮
查看>>
VALSE2019总结(4)-主题报告
查看>>
浅谈 unix, linux, ios, android 区别和联系
查看>>
51nod 1428 活动安排问题 (贪心+优先队列)
查看>>
中国烧鹅系列:利用烧鹅自动执行SD卡上的自定义程序(含视频)
查看>>
Solaris11修改主机名
查看>>
latex for wordpress(一)
查看>>
如何在maven工程中加载oracle驱动
查看>>