Original title: Http://acm.zzuli.edu.cn/problem.php?cid=1099&pid=9
Description
Input
Output
Sample Input31Ten3Ten 5 31 21 351 2 3) 4 53 12 12 42 5Sample OutputYesNoYes
"Code"Transferred from: http://www.cnblogs.com/chenchengxun/p/4443560.html
1#include <stdio.h>2#include <iostream>3#include <stack>4#include <queue>5#include <math.h>6#include <stdlib.h>7#include <cstring>8#include <algorithm>9 using namespacestd;Ten #defineMax (A, B) (A>B?A:B) One #defineMin (A, B) (A<B?A:B) A #defineINF 0XFFFFFFF - #defineMAXN 410 - the intTREE[MAXN][MAXN], N, Flag, VALUE[MAXN], VIS[MAXN]; - - voidDFS (intk) - { + -VIS[K] =1; + for(intI=1; i<=n; i++) A { at if(Tree[k][i] &&!Vis[i]) - { - if(Value[k] <=Value[i]) - DFS (i); - Else -Flag =1; in } - } to } + - intMain () the { * intT, I, A, b; $ Panax NotoginsengCIN >>T; - the while(t--) + { ACIN >>N; theFlag =0; +memset (Tree,0,sizeof(Tree)); -memset (Vis,0,sizeof(Vis)); $ for(i=1; i<=n; i++) $CIN >>Value[i]; - - for(i=1; i<n; i++) the { -Cin >> a >>b;WuyiTREE[A][B] =1; the } - WuDFS (1); - if(flag) Aboutprintf"no\n"); $ Else -printf"yes\n"); - } - return 0; A}
"Binary tree, heap" 15 Light college race-j-Heap