朴素算法枚举两点为o(n^2) ,若用求树重心 采用分治策略可降至n(logn)^2;
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define INF 100010000
const int maxn = 10100;
int n,d[maxn],K;
struct node{
int to,val;
node(int xx=0,int yy=0):to(xx),val(yy){}
};
vector<node> son[maxn];
bool done[maxn];
int Focus,nown,MIN;
void Get_Focus(int u,......
阅读全文