# Joined Subarrays on Tree SOLUTIONS JTSARTR

Page Contents

### Joined Subarrays on Tree SOLUTIONS JTSARTR

Alice thought of a capacity \$F\$, which takes a subjective cluster of numbers \$A = (A_1, A_2, ldots, A_M)\$ as the main contention and is characterized in the accompanying manner:

Consider all sets of subarrays \$(A_i, A_{i+1}, ldots, A_j)\$ and \$(A_k, A_{k+1}, ldots, A_l)\$ with the end goal that:

\$1 le I le j lt k le l le M\$ both subarrays are non-diminishing \$A_j le A_k\$ In the event that there is no such pair of subarrays, \$F(A) = 0\$.

Something else, \$F(A)\$ is the limit of the articulation \$(j-i+1) + (l-k+1)\$ over all such combines of subarrays.

At the end of the day, you have to pick two non-covering non-void subarrays of \$A\$ and connect them in a similar request; the subsequent cluster ought to be non-diminishing and \$F(A)\$ is its most extreme conceivable length.

Bounce moved Alice to tackle the accompanying issue and she needs your assistance.

You are given a tree with \$N\$ vertices (numbered \$1\$ through \$N\$), established at the vertex \$1\$. There is a number written in every vertex; for each substantial \$i\$, how about we signify the whole number written in vertex \$i\$ by \$V_i\$. You ought to pick one vertex ― how about we indicate it by \$v\$. At that point, consider a cluster \$A\$ containing values which are written in vertices on the way from the root to \$v\$ (comprehensive), in a specific order, and figure \$F(A)\$. Locate the most extreme conceivable estimation of \$F(A)\$ which you can get thusly.

Info

The main line of the information contains a solitary whole number \$T\$ signifying the quantity of experiments. The portrayal of \$T\$ experiments follows.

The primary line of each experiment contains a solitary whole number \$N\$.

The subsequent line contains \$N\$ space-isolated numbers \$V_1, V_2, cdot, V_N\$.

Every one of the accompanying \$N-1\$ lines contains two space-isolated numbers \$u\$ and \$v\$ meaning that vertices \$u\$ and \$v\$ are associated by an edge.

Yield

For each experiment, print a solitary line containing one number ― the limit of \$F(A)\$.

Imperatives

\$1 le T le 1,000\$

\$2 le N le 5 cdot 10^5\$

\$|V_i| le 10^9\$ for each substantial \$i\$

\$1 le u, v le N\$

the entirety of \$N\$ over all experiments doesn’t surpass \$10^6\$

Model Input

2 1 5 3

1 2

1 3

3 4

Model Output

Clarification

Model case 1: We pick \$v = 3\$. At that point, \$A(3) = (2, 5)\$; its subarrays \$(2)\$ and \$(5)\$ fulfill every single required condition and the aggregate of their lengths is \$2\$. Its absolutely impossible to get a more noteworthy estimation of the capacity \$F\$.

Related: