Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Importance of Roads

Try to solve the Maximum Total Importance of Roads problem.

Statement

You are given an integer n denoting the number of cities labeled from 00 to n −1- 1. You are also given a 22D integer array roads where roads[i] =[ai,bi]= [a_i, b_i] indicates a bidirectional road connecting cities aia_i and bib_i.

Assign each city an integer value from 11 to n such that each value is used exactly once. The importance of a road is defined as the sum of the values assigned to the two cities it connects.

Return the maximum possible total importance of all roads after assigning the values optimally.

Constraints:

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

  • 1≤1 \leq roads.length ≤5imes104\leq 5 imes 10^4

  • roads[i].length =2= 2

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

  • ai≠bia_i \neq b_i

  • There are no duplicate roads.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Importance of Roads

Try to solve the Maximum Total Importance of Roads problem.

Statement

You are given an integer n denoting the number of cities labeled from 00 to n −1- 1. You are also given a 22D integer array roads where roads[i] =[ai,bi]= [a_i, b_i] indicates a bidirectional road connecting cities aia_i and bib_i.

Assign each city an integer value from 11 to n such that each value is used exactly once. The importance of a road is defined as the sum of the values assigned to the two cities it connects.

Return the maximum possible total importance of all roads after assigning the values optimally.

Constraints:

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

  • 1≤1 \leq roads.length ≤5imes104\leq 5 imes 10^4

  • roads[i].length =2= 2

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

  • ai≠bia_i \neq b_i

  • There are no duplicate roads.