树上差分

bool check(int x)
{
    int cnt=0,dist=0;
    memset(tmp,0,sizeof(tmp));
    for(int i=1; i<=m; i++)
    {
        if(Q[i].Dis > x)
        {
            tmp[Q[i].s]++;
            tmp[Q[i].t]++;
            tmp[Q[i].lca] -= 2;
            dist=chkmax(dist,Q[i].Dis-x);
            cnt++;
        }
    }
    if(!cnt) return true;
    for(int i=n; i>1; i--)
        tmp[grand[kth[i]][0]] += tmp[kth[i]];
    for(int i=2; i<=n; i++)
        if(tmp[i]==cnt && prev[i]>=dist)
            return true;
    return false;
}
 

posted @ 2018-10-25 16:53  hum0r0  阅读(4)  评论(0)    收藏  举报