B. Om Nom and Dark Park
Add some values to some edges on a tree full of two forks. The weights and values on the path of the root node to the leaf node are equal. Minimum number of additions required.
We use nature to solve problems. Investigate sibling nodes. Since they are the same path from the node to the parent node, the value that needs to be added is 2*max (lch,rch)-lch-rch; Add Max (Lch,rch) to the parent node at the same time.
The idea is the most important. Sometimes it's not a question of cleverness, but a question of whether you think.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <stack> One#include <queue> A#include <sstream> -#include <iomanip> - using namespacestd; thetypedefLong Longll; - Const intinf=0x4fffffff; - Const intexp=1e-5; - Const intms= A; + - intnum[1<<MS]; + A intMain () at { - intN; -memset (NUM,0,sizeof(num)); -scanf"%d",&n); - for(intI=2;i< (1<< (n+1)); i++) -scanf"%d",&num[i]); in intans=0; - for(intI= (1<<n)-1;i>0; i--) to { + intlch=num[i<<1]; - intrch=num[i<<1|1]; the intt=Max (lch,rch); *num[i]+=T; $ans+=2*t-lch-rch;Panax Notoginseng } -printf"%d\n", ans); the return 0; +}
B. Om Nom and Dark Park