1 条题解

  • 3
    @ 2022-8-2 9:29:05

    删边(delete)

    题目大意:有一棵树,删去一条边的代价是这条边两端子树里各自权值最大值之和,安排删边顺序使得代价最小,输出最小代价 一道结论题,没什么好说的 ans=timax{ti}+max(txi,tyi)ans=\sum t_{i}-\max \left\{t_{i}\right\}+\sum \max \left(t_{x_{i}}, t_{y_{i}}\right) 证明略

    #include <bits/stdc++.h> 
    using namespace std;
    typedef long long ll;
    ll n, x, y, ans, mx, c[100005];
    int main()
    {
    	scanf("%lld", &n);
    	for (int i = 1; i <= n; i++)
    		scanf("%lld", &c[i]), ans += c[i], mx = max(mx, c[i]);
    	for (int i = 1; i <= n - 1; i++)
    	{
    		scanf("%lld%lld", &x, &y);
    		ans += max(c[x], c[y]);
    	}
    	printf("%lld\n", ans - mx);
    	return 0;
    }
    
    
  • 1

信息

ID
1969
时间
1000ms
内存
256MiB
难度
1
标签
(无)
递交数
41
已通过
33
上传者