2872. Maximum Number of K-Divisible Components
There is an undirected tree with
nnodes labeled from0ton - 1. You are given the integernand a 2D integer arrayedgesof lengthn - 1, whereedges[i] = [ai, bi]indicates that there is an edge between nodesaiandbiin the tree.You are also given a 0-indexed integer array
valuesof lengthn, wherevalues[i]is the value associated with theithnode, and an integerk.A valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by
k, where the value of a connected component is the sum of the values of its nodes.Return the maximum number of components in any valid split.
1 | class Solution { |