Tap here to switch tabs
Problem
Submissions

Problem: Create Components With Same Value

Try to solve the Create Components With Same Value problem.

Statement

There is an undirected tree with nn nodes labeled from 00 to n−1n - 1. You are given an integer array nums of length nn, where nums[i] represents the value assigned to node ii. You are also given a 22D integer array edges of length n−1n - 1, where edges[i] = [ai,bi][a_i, b_i] indicates an undirected edge between node aia_i and node bib_i.

You may delete any number of edges to split the tree into several connected components. The value of a component is the sum of the values of all nodes inside it.

Return the maximum number of edges you can delete such that every resulting connected component has the exact same value.

Constraints:

  • 1≤n≤2⋅1041 \leq n \leq 2 \cdot 10^4

  • nums.length =n= n

  • 1≤1 \leq nums[i] ≤50\leq 50

  • edges.length =n−1= n - 1

  • edges[i].length =2= 2

  • 0≤0 \leq edges[i][0], edges[i][1] ≤n−1\leq n - 1

  • edges represents a valid tree.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Create Components With Same Value

Try to solve the Create Components With Same Value problem.

Statement

There is an undirected tree with nn nodes labeled from 00 to n−1n - 1. You are given an integer array nums of length nn, where nums[i] represents the value assigned to node ii. You are also given a 22D integer array edges of length n−1n - 1, where edges[i] = [ai,bi][a_i, b_i] indicates an undirected edge between node aia_i and node bib_i.

You may delete any number of edges to split the tree into several connected components. The value of a component is the sum of the values of all nodes inside it.

Return the maximum number of edges you can delete such that every resulting connected component has the exact same value.

Constraints:

  • 1≤n≤2⋅1041 \leq n \leq 2 \cdot 10^4

  • nums.length =n= n

  • 1≤1 \leq nums[i] ≤50\leq 50

  • edges.length =n−1= n - 1

  • edges[i].length =2= 2

  • 0≤0 \leq edges[i][0], edges[i][1] ≤n−1\leq n - 1

  • edges represents a valid tree.