Note: This is an approximate problem. There is no exact solution. You must find the most optimal solution. Please, take a look at the sample explanation to ensure that you understand the problem correctly.
Given a set of N nodes, where each node has an integer A[i] associated with it.
Construct a rooted tree using N nodes which is rooted at node 1, such that the value of the given function Z is maximized.
Z=i=N∑i=1[j=N∑j=i+1[F(i,j)]] where F(i,j)=(S(i,j) ⊕ A[LCA(i,j)])+(S(i,j) × A[LCA(i,j)])
Input format
Output format
Constraints
2≤N≤5001≤A[i]≤109
Verdit and Scoring
For the given test case:
Hence, score is equal to 24.