Company: Infosys_12july
Difficulty: medium
Cost of G-Good Sets Problem Description You are given a tree of N nodes, each node has a value A i , written on it. The Parent of each node is denoted by the Par array, where Par[i] denotes the parent of the i-th node. The node whose Parent is 0 is root node and Node 0 does not exist. For some positive integer g, we call a pair of nodes (u, v) g_disconnected if the following conditions hold: Both A u and A v are multiples of g. There is no path between u and v in the tree, such that all the values on this path are multiples of g. For some positive integer g, a set of nodes is considered g_good if the following conditions hold: The set is not empty. All values of the nodes in the set are multiples of g. The nodes of the set are pairwise g_disconnected . In other words, for every pair of nodes u, v in the set such that u is not equal to v, the pair (u, v) is g_disconnected. Two sets of nodes are considered different if there is a node that is contained in one of the sets, but not both of