/*
解题思路:
创建二叉树
遍历检查
这道题其实不需要建立树的结构,因为遍历检查可以在创建时就能完成
需要用到数组做存储结构
*/
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;
struct Node
{
int w1,d1,w2,d2;
Node *lchild,*rchild;
};
bool isEqual;
Node *createTree()
{
int w1,d1,w2,d2;
cin>>w1>>d1>>w2>>d2;
Node *root=(Node *)malloc(sizeof(Node));
root->w1=w1;
root->d1=d1;
root->w2=w2;
root->d2=d2;
if(w1==0)
root->lchild=createTree();
else
root->lchild=NULL;
if(w2==0)
root->rchild=createTree();
else
root->rchild=NULL;
return root;
}
int check(Node *root)
{
if(root->lchild!=NULL)
root->w1=check(root->lchild);
if(root->rchild!=NULL)
root->w2=check(root->rchild);
if(isEqual==true) //这里有个技巧******
isEqual=(root->w1*root->d1==root->w2*root->d2);
/* 另一种表示形式
if(root->w1*root->d1!=root->w2*root->d2)
isEqual=false;
*/
return root->w1+root->w2;
}
int main()
{
//freopen("data.in","r",stdin);
int T;
cin>>T;
while(T--)
{
Node *root=createTree();
isEqual=true;
check(root);
cout<<(isEqual?"YES":"NO")<<endl;
//The outputs of two consecutive cases will be separated by a blank line.
if(T!=0)//仔细看题,WA原因
cout<<endl;
}
return 0;
}