Question: Solve this below problem in Java with proper explanation. Method to use is also given at the end of question Question - You are given
Solve this below problem in Java with proper explanation. Method to use is also given at the end of question
Question
You are given a tree T consisting of N nodes and M edges.
You are given an array A where each node U in the tree have a value AU You are also given a D array E where the ith value denotes that there is an edge between Ei and Ei for all i N
You are given Q queries in a D array Queries which are of the following two types:
Type : U X Set AU X
Type : U V Count the number of nodes that have AU mod X mod where X is the index of the current query.
Find the sum of answers to all queries of Type Since the answer can be very large, return it modulo
Constraints
N
N M N
two
Ai
Eij N
Q
three
Queriesij
Sample Test Cases
Case
Input:
N
M
two
A
E
Q
three
Queries
Output:
Explanation:
Given N M two A E Q three Queries
For the st query the value of mod is to equal
Hence, the sum of queries of type isequalto
Case
Input:
Output:
Explanation:
Given N M two A E Q three Queries
For the st query the answer is equal to
Hence, the sum of queries of type isequalto
Case
Input:
Output:
Explanation:
Given N M two A E Q three Queries
For the st query we update value of node to
For the nd query, the value of and the number of node on path with value equal to mod is
Hence, the sum of queries of type isequalto
Method to use
public static int calcint N int M int two, List A List E int Q int three, List Queries
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
