#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;
}

最新文章

  1. Hello World for U
  2. 关于oralce字符集问题(复制别人的,纯属自己学习)
  3. 在android studio中导入github下载的工程
  4. php保存远程文件到本地的方法
  5. JDK中的Timer和TimerTask详解(zhuan)
  6. Ubuntu 安装 Redis
  7. 用Session实现验证码
  8. CSS实现table td中文字的省略与显示
  9. 张羿给的删除重复数据的mssql语句
  10. Delphi中编写无输出函数名的DLL文件(有点意思)(400多篇博客)
  11. C#入门经典中的SelectionFont属性为null
  12. NOIP2014提高组第二题联合权值
  13. List与Linkedlist、Arrylist、Vector、Map应用
  14. Java IO流学习总结八:Commons IO 2.5-IOUtils
  15. Java学习8——类(对象)之间的关系
  16. button 去掉原生边框
  17. shell的交互式和非交互式登录
  18. C# 判断字符串是否符合十六进制,八进制,二进制和十进制整数格式的正则表达式
  19. thinkphp的自动生成
  20. spoj COT - Count on a tree (树上第K小 LCA+主席树)

热门文章

  1. Android Service 生命周期
  2. POJ2945:Find the Clones——题解
  3. CF498D:Traffic Jams in the Land——题解
  4. UVA.10305 Maximum Product (暴力)
  5. 运行Jar包程序Shell
  6. ES6 利用集合Set解决数组 交集 并集 差集的问题
  7. uploadify图片上传配置
  8. Struts2入门(1)-第一个Struts2程序
  9. Installing JDK7 on Ubuntu
  10. [洛谷P4774] [NOI2018]屠龙勇士