当前位置: 首页 > news >正文

自己做的网站怎么接入网页游戏长沙互联网大厂

自己做的网站怎么接入网页游戏,长沙互联网大厂,南昌建站推广公司,定制网站制作平台Portal. 先找出树上以 S S S 为起点最长的一条链,然后让其他链的长度都和该链对齐即可。 维护每个结点 x x x 的子树最长链 d max ⁡ ( x ) d_{\max}(x) dmax​(x),则每次 DFS 求出最长链之后调整对齐的代价为 d max ⁡ ( x ) − ( d max ⁡ ( s o …

Portal.

先找出树上以 S S S 为起点最长的一条链,然后让其他链的长度都和该链对齐即可。

维护每个结点 x x x 的子树最长链 d max ⁡ ( x ) d_{\max}(x) dmax(x),则每次 DFS 求出最长链之后调整对齐的代价为 d max ⁡ ( x ) − ( d max ⁡ ( s o n x ) + w i ) d_{\max}(x)-(d_{\max}(son_x)+w_i) dmax(x)(dmax(sonx)+wi)

#include <bits/stdc++.h>
using namespace std;
#define int long longconst int maxn=5e5+5;
int head[maxn],V,cnt,mxd[maxn];
struct edge{int to,nxt,w;}e[maxn];void add(int x,int y,int z){e[++cnt]=(edge){y,head[x],z},head[x]=cnt;}void dfs(int x,int fa)
{for(int i=head[x];i;i=e[i].nxt){if(e[i].to==fa) continue;dfs(e[i].to,x),mxd[x]=max(mxd[x],mxd[e[i].to]+e[i].w);}for(int i=head[x];i;i=e[i].nxt){if(e[i].to==fa) continue;V+=mxd[x]-(mxd[e[i].to]+e[i].w);}
}signed main()
{int N,S;cin>>N>>S;for(int i=1,a,b,t;i<N;i++) cin>>a>>b>>t,add(a,b,t),add(b,a,t);dfs(S,0);cout<<V;return 0;
}
http://www.cairui.net.cn/news/7/

相关文章:

  • 中国建设银行官网站下载邢台做wap网站费用
  • 网站建设注意问题家具定制十大名牌
  • 天津建设部网站保温网站建网站建设企业
  • 做平台的网站有哪些内容吗腾讯企业邮箱电脑版
  • 网站建设小程序开发报价如何制作网页设计首页