← All problemsSign in

3772. Maximum Subgraph Score in a Tree

LeetCodeArrayDynamic ProgrammingTreeDepth-First SearchOpen on judge ↗

You are given an undirected tree with n nodes, numbered from 0 to n - 1. It is represented by a 2D integer array edges​​​​​​​ of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given an integer array good of length n, where good[i] is 1 if the ith node is good, and 0 if it is bad. Define the score of a subgraph as the numb

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start