版本比较
题解 CF150E 【Freezing with Style】
正文
增加 4 行删除 4 行
2 行未改动345677891011117 行未改动全部展开12913013113213313313413513613719 行未改动15715815916016116116216316416516616716816916917017117217359 行未改动2 行未改动首先,做这个题目需要学会一个东西:**点分治**
点分治这里不多讲,只说一下大概步骤:
1. 在一棵无根树中选出一个点 $p$ 作为树根 1. 在一棵无根树中选出一个点 $p$ 作为树根
2. 看看有没有经过 $p$ 的合法路径
3. 将 $p$ 删除117 行未改动全部展开 { g[dep[p]]=dis[p],pg[dep[p]]=p; // if(rt==15) printf("points:%d,%d,%d,%d\n",st,p,dep[p],dis[p]); }
Edge(p) { if(y==fa||sgn[y]) continue; dfs(st,y,dep1+1,len1+wei(z),val,p,rt);19 行未改动 int y=srt[i],z=weight[y]; if(sgn[y]) continue; maxd[y]=0; dfs(y,y,1,wei(z),val,x,x);
int now=0;head=tail=1; for(int j=min(U,maxd[y]);j>=0;j--) { while(now<=maxd[srt[i-1]]&&now+j<=U) { while(head<tail&&f[que[tail-1]]<f[now]) tail--; que[tail++]=now;now++;
} while(head<tail&&que[head]+j<L) head++; if(head<tail&&que[head]+j<=U&&f[que[head]]+g[j]>=0) return (ans1=pf[que[head]],ans2=pg[j]),true; }59 行未改动