Enter a tree balance to determine whether the balance is based on the moment equality principle. As shown in Figure 6-5, the so-called torque is equal to the W l l =w R D R, where W L and W R are the weights of the left and right sides, D is the distance. In recursive (first order) mode input: The format of each balance is w L, D L, W R, D R, when W L or W R is 0 o'clock, means that the "weight" is actually a sub scale, then the child balance will be described. When the W l =w r = 0 o'clock, the Zoozi balance is described first, then the right sub balance.
Sample Input
1
0 2 0 4
0 3 0 1
1 1 1 1
2 4 4 2
1 6 3 2
Sample Output
YES
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; Const int MAXN = 100005;
#define MST (S,Q) memset (s,q,sizeof (s)) #define Lchild id<<1 #define RCHILD (id<<1) +1 using namespace std;
BOOL Solve (int &w) {int W1, D1, W2, D2;
CIN >> W1 >> D1 >> W2 >> D2;
BOOL Sign1 = 1, sign2 = 1; if (!
W1) Sign1 = Solve (W1); if (!
W2) sign2 = Solve (W2);
W = W1 + W2;
return sign1 && sign2 && (W1 * D1 = = W2 * D2);
int main () {int T, W;
Cin >> T;
while (t--) {if (Solve (W)) cout << "yes\n";
else cout << "no\n";
if (T) cout << Endl; }
}