NeetCode #618LC-2872HardGraphs
← Back to All Problems

#618 · #2872 · Maximum Number of K-Divisible Components(可以被 K 整除连通块的最大数目)

📌 Problem Statement & Constraints

You are given a tree of n nodes, edges, values for each node, and an integer k. Remove some edges so that every resulting component has a sum divisible by k. Return the maximum number of components. Constraints: 1 <= n <= 3 * 10^4, 1 <= k <= 10^9, 1 <= values[i] <= 10^9; the total sum is divisible by k.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!