Practice Maximum Sum of Edge Values in a Graph
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an undirected connected graph of n nodes, numbered from 0 to n - 1. Each node is connected to at most 2 other nodes. The graph consists of m edges, represented by a 2D array edges, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. You have to assign a unique value from 1 to n to each node. The value of an edge will be the product of the values assigned to the two nodes it connects. Your score is the sum of the values of all edges in the graph. Return the maximum score you can achieve.
Source: Maximum Sum of Edge Values in a Graph on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 4, edges = [[0,1],[1,2],[2,3]]
23
# Example 2
n = 6, edges = [[0,3],[4,5],[2,0],[1,3],[2,4],[1,5]]
82
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Sum of Edge Values in a Graph.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.