Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of Edge Values in a Graph

Try to solve the Maximum Sum of Edge Values in a Graph problem.

Statement

You are given an integer n representing the number of nodes in a connected undirected graph, with nodes labeled from 00 to n −1- 1. You are also given a 22D integer array edges, where edges[i] =[ai,bi]= [a_i, b_i] denotes an undirected edge between node aia_i and node bib_i.

You must assign each node a distinct integer from 11 to n. The value of an edge is the product of the values assigned to its endpoints.

Return the maximum possible sum of all edge values across the entire graph.

Constraints:

  • 1≤1 \leq n ≤5imes104\leq 5 imes 10^4

  • m ==== edges.length

  • 1≤1 \leq m ≤\leq n

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

  • 0≤ai,bi<0 \leq a_i, b_i < n

  • ai≠bia_i \neq b_i

  • There are no repeated edges.

  • The graph is connected.

  • Each node is connected to at most 22 other nodes.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of Edge Values in a Graph

Try to solve the Maximum Sum of Edge Values in a Graph problem.

Statement

You are given an integer n representing the number of nodes in a connected undirected graph, with nodes labeled from 00 to n −1- 1. You are also given a 22D integer array edges, where edges[i] =[ai,bi]= [a_i, b_i] denotes an undirected edge between node aia_i and node bib_i.

You must assign each node a distinct integer from 11 to n. The value of an edge is the product of the values assigned to its endpoints.

Return the maximum possible sum of all edge values across the entire graph.

Constraints:

  • 1≤1 \leq n ≤5imes104\leq 5 imes 10^4

  • m ==== edges.length

  • 1≤1 \leq m ≤\leq n

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

  • 0≤ai,bi<0 \leq a_i, b_i < n

  • ai≠bia_i \neq b_i

  • There are no repeated edges.

  • The graph is connected.

  • Each node is connected to at most 22 other nodes.