使用递归直接处理信息并建树,同时判断是否满足杠杆定理
//UVa 839
#include <cstdio>
bool flag;
int build() {
int wl, dl, wr, dr;
scanf("%d%d%d%d", &wl, &dl, &wr, &dr);
if (wl == 0) {
wl = build();
}
if (wr == 0) {
wr = build();
}
if (wl * dl != wr * dr) {
flag = false;
}
return wl + wr;
}
int main(int argc, char const *argv[]) {
int t;
scanf("%d", &t);
while (t--) {
flag = true;
build();
puts(flag == true ? "YES" : "NO");
if (t) {
putchar('\n');
}
}
return 0;
}