点分治+算法模板

#include
using namespace std;
#define Sheryang main
#define TYPE int
const int maxn=1e5+7;
typedef long long ll;
const int mod=1e9+7;
void Smax(TYPE &a,TYPE b){if(ab) a=b;}
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

struct edge{
    int w,to,next;
}edge[maxn];
int head[maxn],m,n,T;

void add_edge(int u,int v,int w){
    edge[++m].next=head[u];
    head[u]=m;
    edge[m].to=v;
    edge[m].w=w;
}

int vis[maxn],a[maxn],dis[maxn],len,ans[maxn];
namespace cent{ ///求树的重心的封装函数
    int n,rt,son[maxn],maxl;
    void dfs(int u,int fa){
        son[u]=1;
        int ml=0;
        for(int i=head[u];~i;i=edge[i].next){
            int v=edge[i].to;
            int w=edge[i].w;
            if(v==fa || vis[v]) continue;
            dfs(v,u);
            son[u]+=son[v];
            Smax(ml,son[v]-1);
        }
        Smax(ml,n-son[u]);
        if(ml

 

你可能感兴趣的:(点分治,树状结构,模板算法)