Practice Maximum Total Importance of Roads
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 integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1. You are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi. You need to assign each city with an integer value from 1 to n, where each value can only be used once. The importance of a road is then defined as the sum of the values of the two cities it connects. Return the maximum total importance of all roads possible after assigning the values optimally.
Source: Maximum Total Importance of Roads on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]]
43
# Example 2
n = 5, roads = [[0,3],[2,4],[1,3]]
20
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Total Importance of Roads.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.