Milk Visits

타입이 붙은 트리에서 M개의 질의마다 두 정점 사이 경로 위에 요청한 타입의 소가 하나라도 있는지 판별한다.

어려움8트리DFS누적 합이분 탐색아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Farmer John is planning to build NN (1N1051 \leq N \leq 10^5) farms that will be connected by N1N-1 roads, forming a tree (i.e., all farms are reachable from each-other, and there are no cycles). Each farm contains a cow with an integer type T_iT\_i between 11 and NN inclusive.

Farmer John's MM friends (1M1051 \leq M \leq 10^5) often come to visit him. During a visit with friend ii, Farmer John will walk with his friend along the unique path of roads from farm A_iA\_i to farm B_iB\_i (it may be the case that A_i=B_iA\_i = B\_i). Additionally, they can try some milk from any cow along the path they walk. Since most of Farmer John's friends are also farmers, they have very strong preferences regarding milk. Each of his friends will only drink milk from a certain type of cow. Any of Farmer John's friends will only be happy if they can drink their preferred type of milk during their visit.

Please determine whether each friend will be happy after visiting.

입력

The first line contains two integer NN and MM.

The second line contains NN space-separated integers T_1,T_2,,T_N.T\_1,T\_2,\ldots, T\_N. The type of the cow in the ii-th farm is denoted by T_i.T\_i.

The next N1N-1 lines each contain two distinct integers XX and YY (1X,YN1 \leq X, Y \leq N), indicating that there is an edge between farms XX and YY.

The next MM lines contain integers A_iA\_i, B_iB\_i, and C_iC\_i. A_iA\_i and B_iB\_i represent the endpoints of the path walked during friend ii's visit, while C_iC\_i (1C_iN1\le C\_i\le N) indicates the type of cow whose milk the friend enjoys drinking.

출력

Print a binary string of length M.M. The iith character of the string should be '1' if the iith friend will be happy, or '0' otherwise.