树的直径 二分答案
这道题和树网的核数据加强版很像啊
首先,在不考虑路径长度的情况下,最优的路径就应该在树的直径上,答案就是离树的直径最远的点到直径的距离。
因此,YY一下,这道题的路径也应该造在直径上。(因为我太菜所以严格证明我并不会)
那么我们只要把直径找出来,再以离树的直径最远的点到直径的距离为l,树的直径的长度为r二分答案即可。
具体实现见代码:
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 300005
#define F inline
using namespace std;
struct edge{ int next,to,dis; }ed[N<<1];
int n,m,k,s,t,l,r,num,sum[N],h[N],que[N],pre[N],dis[N];