UV 12452 Plants vs. Zombies hd sp tree dp (Water
Question link: Click the open link
Question:
Tree with given n points [0, n)
At first, all edges are colorless.
There are three types of operations:
1. Select a vertex to dye the connected edge. The cost is 100.
2. It takes 175 to select two edges connected by a dot-dye.
3. It takes 500 to select a vertex to dye all edges connected to it.
Q:
Minimum Cost of dyeing all edges. Edges can be repeatedly colored, and vertices can only be operated once.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Template
Inline bool rd (T & ret) {char c; int sgn; if (c = getchar (), c = EOF) return 0; while (c! = '-' & (C <'0' | c> '9') c = getchar (); sgn = (c = '-')? -1:1; ret = (c = '-')? 0 :( c-'0'); while (c = getchar (), c> = '0' & c <= '9 ') ret = ret * 10 + (c-'0'); ret * = sgn; return 1;} template
Inline void pt (T x) {if (x <0) {putchar ('-'); x =-x;} if (x> 9) pt (x/10); putchar (x % 10 + '0');} using namespace std; typedef long ll; const int N = 10100; const ll inf = 1e10; struct Edge {int to, nex;} edge [N <1]; int head [N], edgenum; void add (int u, int v) {Edge E = {v, head [u]}; edge [edgenum] = E; head [u] = edgenum ++;} void init () {memset (head, -1, sizeof head); edgenum = 0;} int n; ll dp [N] [2];/* dp [I] [0]: dp [I] [1] is selected for the parent edge of I. */void up (ll & x, const ll & y) {if (y