This page is still under construction.

Parts of this page are still being built. What you see may change.

Cheap Flights

Time limit2sMemory limit1024 MB

Summary
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 NN 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 NN and the number of profitable routes MM. The cities are labeled from 11 to NN.

Each of the next MM lines contains three integers aia_i, bib_i, and pip_i: aia_i and bib_i are the two cities joined by the ii-th route, and pip_i is its profitability. No two routes connect the same pair of cities.

Output

Output a single integer: the maximum possible profit.

Constraints

  • 1≤N≤3000001 \le N \le 300000
  • 1≤M≤5000001 \le M \le 500000
  • 1≤ai,bi≤N1 \le a_i, b_i \le N
  • 1≤pi≤10000000001 \le p_i \le 1000000000

Examples3

  1. Example 1

    Input
    5 4
    1 2 1
    1 3 2
    1 4 1
    2 4 1
    
    Expected output
    4
    
  2. Example 2

    Input
    7 9
    1 2 2
    2 3 5
    2 4 3
    2 5 5
    2 6 4
    4 5 8
    4 7 6
    5 6 2
    5 7 6
    
    Expected output
    21
    
  3. Example 3

    Input
    7 8
    1 2 10
    1 4 3
    2 3 20
    2 4 8
    3 4 12
    4 5 1
    4 6 2
    4 7 3
    
    Expected output
    40