思路:要找一个最大距离最小的点,那么有2个方向1.这u点下面最远距离2.这个u点上面的最远距离,这里向上走有2种走法,一直是直接求u点的子节点没有访问过求向上和向下的最大值,访问过则求向上最大值和向下次大值的最大值,这里需要记录一下路径用p1[i]记录最大距离从i经过的话是由那个点过来的,p2[i]记录次大。
#pragma GCC optimize(2)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<iomanip>
#include<cstring>
#include<time.h>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false)
#define space putchar(' ')
#define enter putchar('\n')
#define lson root<<1
#define rson root<<1|1
typedef pair<int,int> PII;
const int mod=1e9+7;
const int N=2e6+10;
const int M=1e3+10;
const int inf=0x3f3f3f3f;
const int maxx=2e5+7;
const double eps=1e-6;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b)