#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. POJ1284:Primitive Roots——题解

    http://poj.org/problem?id=1284 给一个奇质数p,求p的原根数量. 有一个结论:当正整数n存在原根时,其一共有phi(phi(n))个不同余的原根. 所以答案为phi(p- ...

  2. BZOJ4872:[SHOI2017]分手是祝愿——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=4872 https://www.luogu.org/problemnew/show/P3750 Zei ...

  3. 【贪心/DP/单调队列】【CF1029B】Creating the Contest

    Description 给你一个单调不下降的长度为n的序列,请你找出一个最长的子序列,满足找出的子序列中,\(A_i<=A_{i-1}~\times~2\),其中i为下标,A为找出的子序列.对于 ...

  4. vim 打开中文乱码

    [root@yu ~]# find / -name vimrc/etc/vimrc [root@yu ~]# vim /etc/vimrc set fileencodings=utf-8,gb2312 ...

  5. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀

    A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Android 一些系统参数的获取

    //获取网络类型 2G/3G/WIFI public String getNetworkType(){ String mNetWorkType = ""; Connectivity ...

  7. Java并发之同步原语

    volatile: 定义:Java编程语言允许线程访问共享变量,为了确保共享变量内被准确和一致性地更新,线程应该确保通过排它锁单独获得这个变量.根据volatile的定义,volatile有锁的语义. ...

  8. Beautiful Soup的一些中文资料

    如果你着急用的话,可以看下这个简略版的,非常简单: 转自  人世间http://rsj217.diandian.com/post/2012-11-01/40041235132 当然,强烈推荐你看一下的 ...

  9. MongoDB入门(6)- 我们自己封装的MongoDB-C#版本

    Wisdombud.Mongo 包含内容 MongoDB.Bson.dll MongoDB.Bson.xml MongoDB.Driver.dll MongoDB.Driver.xml Wisdomb ...

  10. LightOJ 1097 - Lucky Number 线段树

    http://www.lightoj.com/volume_showproblem.php?problem=1097 题意:一个自然数序列,先去掉所有偶数项,在此基础上的序列的第二项为3,则删去所有3 ...