In this problem’s full solution, the USACO Guide uses DAG with transition state:
if (min(du[node], dp[0][par]) + min(dv[node], dp[1][par]) <=
dp[0][node] + dp[1][node]) {
dp[0][node] = min(du[node], dp[0][par]);
dp[1][node] = min(dv[node], dp[1][par]);
}
when there are multiple parents that can reach on the DAG. Why is comparing the sum of the dpU and dpV optimal? What if one parent has {dpU, dpV} = {2,2} and another has {1,4}. Here, the algorithm would pick {2,2} because the sum is less.
If some descendent of our node in the DAG has {10,1} , then choosing the {1,4} would have given us {1,1} with sum = 2 instead of {2,1}. How does the algorithm handle this case? My guess was that by running the DP from s ->t and t->s, but when I kept on s->t, it still passed.