2872. Maximum Number of K-Divisible Components
There is an undirected tree with
n
nodes labeled from0
ton - 1
. You are given the integern
and a 2D integer arrayedges
of lengthn - 1
, whereedges[i] = [ai, bi]
indicates that there is an edge between nodesai
andbi
in the tree.You are also given a 0-indexed integer array
values
of lengthn
, wherevalues[i]
is the value associated with theith
node, 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 { |