/*
HDU 4679 Terrorist’s destroy
给一棵树,任意删一条边,树分成了两个部分(a,b),求min( max(a.直径,b.直径) * v.w )
最大直径乘以边权 积的最小值
解法:
先找出整棵树的直径所在,即两个端点ds de
然后保存每个点到ds和de之间的距离 dds[] dde[]
然后从ds(de)开始搜
每个点保存子树中到de(ds)之间距离的最大值mde[](mds[]),这里要用到dds[]和dde[]
然后枚举删边,从ds(或de)开始搜
当删father,child之间的一条边的时候,分成了两个子树,我们的max(mde[father],mds[child])就是两个子树的最大直径
然后就没有然后了。。。。
几乎每一部操作都要搜两次
*/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <cmath>
#include <set>
#define CLR(a,v) memset(a,v,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const int N = 1e5+10;
struct node{
int hid , w , pi
【解题报告】HDU 4679 Terrorist’s destroy -- 树形dp 删一边求两子树直径
最新推荐文章于 2022-11-15 12:45:27 发布