#include<algorithm>
#include<iostream>
#include<cstdio>
#define inf 0x3f3f3f3f
#define N 500005
#define root true
using namespace std; typedef pair<int ,int > Pair; struct Edge{
int v,c,nxt;
}e[N<<1];
int head[N],tot; void AddEdge(int u,int v,int c){
e[++tot]=(Edge){v,c,head[u]};head[u]=tot;
e[++tot]=(Edge){u,c,head[v]};head[v]=tot;
} int k;
int n,m;
int dep[N];
int pos[N];
Pair other[N];
int f[N][20]; int dfs(int u,int fa){
f[u][0]=fa;dep[u]=dep[fa]+1;
for(int i=head[u];i;i=e[i].nxt)
if(e[i].to!=fa){
dfs(e[i].to,u);
d[e[i].to]=d[u]+e[i].c;
}
} int DFS(int u){
if();
} Pair depth(int pos,int tim){
for(int i=20;i>-1;--i)
if(f[pos][i]&&tim>(d[pos]-d[f[pos][i]-1]))
tim-=d[pos]-d[f[pos][i]-1],pos=f[pos][i];
return make_pair(pos,tim);
} queue<Pair>que; bool check(int ans){
que.clear();
for(int i=1;i<=m;++i){
other[i]=depth(pos[i],ans);
if(other[i].first==root)
que.push(other[i]);
}
DFS(1);
} int main(){
scanf("%d",&n);int a,b,c;
for(int i=1;i<n;++i){
scanf("%d%d%d",&a,&b,&c);
AddEdge(a,b,c);
}
dfs(1,0);
for(int i=1;i<=20;++i)
for(int j=1;j<=n;++j)
fa[j][i]=fa[fa[j][i-1]][i-1];
scanf("%d",&m);
for(int i=1;i<=n;++i)
scanf("%d",pos[i]);
int l=1,r=inf,mid;
while(l<r){
mid=(l+r)>>1;
if(check(mid))
r=mid-1;
else l=mid+1;
}
return 0;
}

3.4Code的更多相关文章

  1. ASP.NET MVC 4.0 学习4-Code First

    之前我們需要用到的數據,通過添加Entity實體數據模型把數據庫中需要的Database拉到項目中如下圖, 而就是Code First就是相對於這種處理數據的方法而言的 Code First更加準確的 ...

  2. ent orm笔记4---Code Generation

    在前面几篇文章中,我们经常使用的可能就是entc这个命令了,entc这个工具给带来了很多功能,这篇文章主要整理关于ent orm 中Code Generation 之前的例子中有个知识点少整理了,就是 ...

  3. Nodejs中关于模块的总结

    关于Nodejs中的模块 概念 Nodejs在ECMAScript的基础上扩展并封装了许多高级特性,如文件访问.网络访问等,使得Nodejs成为一个很好的Web开发平台.基于Nodejs这个平台将We ...

  4. Nodejs第一天-{Nodejs基础 深刻理解浏览器 环境变量 基础语法}

    Nodejs第一天 1.什么是Nodejs ​ Nodejs是一个可以运行(解析)ECMAScript的环境; ​ ECMAScript是规定了一些列的语法 ,这些语法想要解析的执行就需要放在某个环境 ...

  5. matlab boundaries和fchcode函数无法执行的解决办法 未定义与 'double' 类型的输入参数相对应的函数 'boundaries'

    在测试代码时发现,自己的matlab无法执行Freeman链码函数: boundaries和fchcode函数都无法正常运行: 需要在自己的工作目录中添加如下函数: boundaries   fchc ...

随机推荐

  1. Android Appliction 使用解析

    Application Base class for those who need to maintain global application state. You can provide your ...

  2. 【BZOJ1941】Hide and Seek(KD-Tree)

    [BZOJ1941]Hide and Seek(KD-Tree) 题面 BZOJ 洛谷 题解 \(KD-Tree\)对于每个点搜一下最近点和最远点就好了 #include<iostream> ...

  3. BZOJ3653 & 洛谷3899:谈笑风生——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3653 https://www.luogu.org/problemnew/show/P3899 设 ...

  4. NOIP2016Day1T3换教室(floyd+期望dp)

    啊...这个时间写博客,明天还要上学,整个人都不好了... 这是我写的第一道期望题hiahiahia... 题目大意就不说了QWQ 80分儿做法:先floyd,爆搜枚举哪些点取,求出答案,效率O(C( ...

  5. JavaScript滚动条的制作

    效果演示   这个效果的制作是借助setTimeout的第三个参数.setTimeout/setInterval,这两个函数相信前端开发同学都很熟悉.它们在非IE(6-9)浏览器中还可以如下使用: v ...

  6. AIDL 简单实现

    实现步骤1.建立一个aidl文件,在里面定义好接口,注意里面不能写public修饰符,同接口一样,包名要一致. package com.systemset.aidl; interface ILight ...

  7. tcpdump抓取ftp密码

    步骤: 1.登陆ftp服务器,执行命令: tcpdump -i wlan0 -w password.bin -c 500 port 21 2.有人登陆后,执行: tcpdump -v -XX -r p ...

  8. Web前端工程师-优秀简历汇总

    Web前端工程师-优秀简历汇总   1. http://www.linqing07.com/resume.html   2.  http://www.flqin.com/#page2   3.  ht ...

  9. pc扫码支付

    https://www.cnblogs.com/shengyu-kmust/p/5228261.html https://pay.weixin.qq.com/wiki/doc/api/native.p ...

  10. overflow:auto产生的滚动条在安卓系统下能平滑滚动,而在ios下滚动不平滑

    由于系统的问题,加上-webkit-overflow-scrolling : touch; 即可解决平滑滚动问题