電気回路作成のアルゴリズム問

最近トップコーダーの最適化問題を挑戦しています。It was initially thought I could assign one of the minimal resistances as one input to each B gate, but this discounted the possibility of nested gates. For example, if 2 B gates are children of another B gate, 3 of the 4 inputs to the lead gates are dropped.
It seems one way is to embed the A-gate depth into the tree data structure and, for the topmost B gate, select the path of greatest A gate depth. A門の深さが最も多い方向を選択する方法です。for nested B gates, again select the optimal path based on the number of A gates. When the paths are determined, assign the conductor values to leaves on the optimal path in order from top to bottom node and max to min value. Thus, only the minimal values will be discarded by the B gates.こちらの回答は正しくビーゲートの道を選択したが累計の数字が正解に合わなかった。でも見直せば道の選択が実際に正しくない。The key attribute to assess is not A gate depth but number of terms summed. Upon changing "aDepth" to "termsSummed" and changing the calculation of this property value for an a gate to be the sum of the attributes of its paths, the code returns the correct output.