博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【BZOJ1468】Tree
阅读量:6922 次
发布时间:2019-06-27

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

Description

给你一棵TREE,以及这棵树上边的距离.问有多少对点它们两者间的距离小于等于K

Input

N(n<=40000) 接下来n-1行边描述管道,按照题目中写的输入 接下来是k

Output

一行,有多少对点之间的距离小于等于k

Sample Input

7
1 6 13
6 3 9
3 5 7
4 1 3
2 4 20
4 7 2
10

Sample Output

5
 
又是一道点分治的题,方法同聪聪可可。
1 #include
2 #include
3 using namespace std; 4 const int N=40010; 5 int deep[N],head[N],son[N],f[N],d[N],root,ans,n,sum,cnt,k; 6 bool vis[N]; 7 struct ee{
int to,next,w;}e[N*2]; 8 void insert(int u,int v,int w){ 9 e[++cnt].to=v;e[cnt].next=head[u];e[cnt].w=w;head[u]=cnt;10 }11 12 void getroot(int x,int fa){13 son[x]=1;f[x]=0;14 for (int i=head[x];i;i=e[i].next){15 int v=e[i].to;16 if (vis[v]||v==fa) continue;17 getroot(v,x);18 son[x]+=son[v];19 f[x]=max(f[x],son[v]);20 }21 f[x]=max(f[x],sum-f[x]);22 if (f[x]

 

转载于:https://www.cnblogs.com/wuminyan/p/5140596.html

你可能感兴趣的文章
07 jQuery EasyUI 之Resizable调整大小
查看>>
Silent Installation静默安装11gR2 DB SERVER单机并手动建库步骤
查看>>
微信视频直播方案的搭建
查看>>
Hbase 原理
查看>>
K8S 集群安装
查看>>
Unity版本号:5.5.0
查看>>
云计算数据中心运维管理要点
查看>>
cisco 4507 (生产环境)
查看>>
Jedis操作redis--Set篇
查看>>
48. 源代码解读-RocketMQ-client接收消息流程
查看>>
Juery 基础
查看>>
wdcp后台访问安全设置即限制域名/IP访问设置及清除方法
查看>>
memcache
查看>>
jquery 删除字符串最后一个字符的方法
查看>>
CentOS使用光盘rpm安装g++
查看>>
Asp.net页面和Html页面之间的关系
查看>>
解决远程无法登陆mysql服务器的问题和重置密码
查看>>
zabbix监控mysql主从状态
查看>>
mycat启动服务,后台日志报错Bit Server VM warning: ignoring option MaxPermSize
查看>>
Bash的历史命令 history
查看>>