Skip to content

Commit

Permalink
Update ac-SelectEdges.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGamingMousse authored Jan 16, 2025
1 parent cdcd6de commit 8d99347
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions solutions/gold/ac-SelectEdges.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ To solve this problem, we write a tree DP. Consider that the only factor we
need to differentiate nodes on is whether or not we can connect a given node
to its parent. Thus, our DP state is the following:

- $\text{dp}[u][0]$ is the best result in the subtree of $u$ if we can connect $u$ to its parent
- $\text{dp}[u][1]$ is the best result in the subtree of $u$ if we can't connect $u$ to its parent
- $\texttt{dp}[u][0]$ is the best result in the subtree of $u$ if we can connect $u$ to its parent
- $\texttt{dp}[u][1]$ is the best result in the subtree of $u$ if we can't connect $u$ to its parent

For a given node $u$, the "gain" we get from adding this node in is:

$$
(w + \text{dp}[u][0]) - \text{dp}[u][1]
(w + \texttt{dp}[u][0]) - \texttt{dp}[u][1]
$$

Thus, we want to use our $d[u]$ allowed edges on the nodes that have the most
benefit when adding an edge to them. Note that we handle the cases for
$\text{dp}[u][0])$ and $\text{dp}[u][1]$ pretty similarly.
$\texttt{dp}[u][0])$ and $\texttt{dp}[u][1]$ pretty similarly.

## Implementation

Expand Down

0 comments on commit 8d99347

Please sign in to comment.