This question is a little tree dp meaning (Gangster light spray
I just got no idea when this question only know half the answer to this question
Why is half the answer? ? ?
topic:
Currently the construction of the track program has not been determined. Your task is to design a
Species track construction scheme, such that the track construction m in length of
the smallest maximum length of the track (i.e., track m shortest track
length as large as possible)
Minimum or maximum ...... ...... maximum usually occurs at a minimum is half the answer.
How dichotomous answer? ? ?
This question is asked of the minimum length of the maximum, it must be
half the length, that is when we can begin to set up
l = 0, r = 最大值 mid = (l + r) / 2
We obtained a length greater than equal to each track we call mid valid, and if valid track number is greater than m, then the described mid <= true answer, so we let l = mid + 1, two points continues, otherwise let r = mid.
How to transfer? ? ?
In fact, the beginning of the blind do when I have not found this to be a tree dp (escape
There is such a map, we start to consider each subtree
We assume that this node 2 subtree rooted in, from 5-2 and then this path 7 is to meet the legal conditions of the track, then we can add a direct answer, then these two edges deleted.
It may be a few remaining side.
We can see that if you use this node 2 to constitute legal length of the track, either 2 node starts to go up from 0 to Couchu legal length, either pick a side 2 below (we first assumed to be 6 to 2 sides) up to join in, can only pick a side, then we must be to pick a never used the longest side.
n = 50000, we can use to achieve an orderly lower_bound multiset side of each node and find out if you can make up one edge legal side.
This can be achieved so
int dfs(int x, int fa, int mid) {
int len = 0;
multiset<int> s;
for (int i = p[x]; i != -1; i = e[i].nxt) {
int v = e[i].v, w = e[i].w, l;
if (v == fa) {
continue;
}
l = dfs(v, x, mid) + w;
opt[x] += opt[v];
if (l >= mid) {
opt[x]++;
} else {
s.insert(l);
}
}
while (!s.empty()) {
int now = (*s.begin());
s.erase(s.begin());
multiset<int>::iterator it = s.lower_bound(mid - now);
if (it != s.end()) {
s.erase(it);
opt[x]++;
} else {
len = now;
}
}
return len;
}
As Figure chrysanthemum words may get caught? ? ? I have not tried, especially if you are concerned, then you can judge it, just once and then sort lower_bound OK.
8.19 update
有同学不知道菊花图是什么
就是介个东西QWQ
菊花图通常会被卡,所以需要特判或者寻找更高效算法( 一般是特判辣, 因为菊花图上的问题大部分比较简单的 )
好像也没多少树上dp