Cheap Flights
Time limit2sMemory limit1024 MB
Given a weighted graph, pick a set of edges with pairwise nonempty intersection maximizing total weight.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Brute force, Combinatorics
- Solved
- No attempts yet
Problem
Justas built a passenger airplane, and now he wants to start a low-cost airline called Justas Airlines.
Justas made a list of the cities most popular among tourists and worked out which routes between these cities would be profitable. Each route connects two cities, and its profitability is the number of Euros per month that Justas Airlines would earn by operating it.
The routes must be chosen so that every two chosen routes share a common city. Compute the maximum profit that Justas Airlines can make in one month.
Input
The first line contains the number of cities and the number of profitable routes . The cities are labeled from to .
Each of the next lines contains three integers , , and : and are the two cities joined by the -th route, and is its profitability. No two routes connect the same pair of cities.
Output
Output a single integer: the maximum possible profit.