Tap here to switch tabs
Problem
Submissions

Problem: Maximum Star Sum of a Graph

med
30 min
Try to solve the Maximum Star Sum of a Graph problem.

Statement

There is an undirected graph consisting of n nodes indexed from 00 to n −1- 1. You are given an integer array vals of length n, where vals[i] represents the value of node i. You are also given a 22D integer array edges, where edges[i] = [a_i, b_i] represents an undirected edge between node a_i and node b_i.

Additionally, you are given an integer k.

A star graph is a subgraph containing a center node and at most k of its neighbors. The star sum is the sum of the values of the center node and all included neighbor nodes.

Return the maximum star sum among all possible star graphs in the given graph.

Constraints:

  • n ==== vals.length

  • 1≤1 \leq n ≤105\leq 10^5

  • −104≤-10^4 \leq vals[i] ≤104\leq 10^4

  • 0≤0 \leq edges.length ≤min⁡(\leq \min(n ⋅(\cdot (n −1)/2,105)- 1) / 2, 10^5)

  • edges[i].length ==2== 2

  • 0≤0 \leq a_i, b_i ≤\leq n −1- 1

  • a_i ≠\neq b_i

  • 0≤0 \leq k ≤\leq n −1- 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Star Sum of a Graph

med
30 min
Try to solve the Maximum Star Sum of a Graph problem.

Statement

There is an undirected graph consisting of n nodes indexed from 00 to n −1- 1. You are given an integer array vals of length n, where vals[i] represents the value of node i. You are also given a 22D integer array edges, where edges[i] = [a_i, b_i] represents an undirected edge between node a_i and node b_i.

Additionally, you are given an integer k.

A star graph is a subgraph containing a center node and at most k of its neighbors. The star sum is the sum of the values of the center node and all included neighbor nodes.

Return the maximum star sum among all possible star graphs in the given graph.

Constraints:

  • n ==== vals.length

  • 1≤1 \leq n ≤105\leq 10^5

  • −104≤-10^4 \leq vals[i] ≤104\leq 10^4

  • 0≤0 \leq edges.length ≤min⁡(\leq \min(n ⋅(\cdot (n −1)/2,105)- 1) / 2, 10^5)

  • edges[i].length ==2== 2

  • 0≤0 \leq a_i, b_i ≤\leq n −1- 1

  • a_i ≠\neq b_i

  • 0≤0 \leq k ≤\leq n −1- 1