Question: Problem Submissions Spltting Edges 1 0 0 . 0 % Submissions: 1 + Points: 3 0 You have been given an undirected tree with N
Problem
Submissions
Spltting Edges
Submissions:
Points:
You have been given an undirected tree with N nodes and N edges, each node has a value values; either or When you cut an edge, the tree gets split into two components and this splitting is valid if both components satisfy the below property.
Property : Let X be the product of all the node values in the component then, X should be divisible by
In simple words, you are given an array Values which, contains the value of each node and an Edges array which contains N undirected edges of the tree. Find the number of valid splits of the gliven tree ie number of edges that can be removed such that components formed after splitting follows the above given property.
NOTE ; You need to split the tree into two components only lie. only one edge removal is possible at once.
Input:
Values
Edges
Output:
Explanation:
Input:
Explanation:
Geek can split the tree at edge and the resulting two components will have product divisible by
Similarly, Geek can also split the tree at edge and the resulting two components will have product divisible by
Similarly, Geek can also split the tree at edge and the resulting two components will have product divisible by
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
