<center style="color&#58;rgb&#40;51&#44;51&#44;51&#41;&#59;font&#45;family&#58;&#39;Helvetica Neue&#39;&#44; Helvetica&#44; Arial&#44; sans&#45;serif&#59;font&#45;size&#58;14px&#59;background&#45;color&#58;rgb&#40;255&#44;255&#44;255&#41;&#59;">

问题 I: 堆

时间限制: 1 Sec   内存限制: 128 MB
</center>

题目描述

输入

输出

样例输入

3
1
10
3
10 5 3
1 2
1 3
5
1 2 3 4 5
3 1
2 1
2 4
2 5

样例输出

Yes
No
Yes
#include <stdio.h>
#include <string.h>
int main()
{
	int a[110], s[110][110], x, y, n, i, j, t, ans;
	scanf("%d", &t);
	while (t--)
	{
	    memset(s, 0, sizeof(s));
		scanf("%d", &n);
		for (i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		for (i = 1; i < n; i++)
		{
			scanf("%d%d", &x, &y);
			s[x][y]++;
		}
		ans = 1;
		for (i = 1; i < 101; i++)
		{
			for (j = 1; j < 101; j++)
			{
				if (s[i][j] != 0)
				{
					if (i > j && a[i] < a[j] || i < j && a[i] > a[j])
					ans = 0;
				}
			}
			if (!ans)
				break;
		}
		if (ans)
			printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}