시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB50151128.947%

문제

Justas built a passenger airplane, and now he wants to start a low cost airline, called Justas Airlines.

Justas made a list of the N most popular cities among tourists, and calculated which routes between these cities would be profitable. Each route connects two cities. The profitability of the route indicates how many Euros per month Justas Airlines would earn by operating the route.

Routes have to be chosen so that any two routes have one city in common. Calculate the maximum profit that Justas Airlines can make in one month.

입력

The first line shows the number of cities N, and the number of profitable routes M. Cities are labeled 1 to N. The following M lines contain three numbers each – ai, bi, and pi, where ai and bi are the two cities joined by the i-th routes, and pi is the profitability of the route. No two routes connect the same pair of cities.

출력

Output a single number: the maximum possible profit.

제한

  • 1 ≤ N ≤ 300 000
  • 1 ≤ M ≤ 500 000
  • 1 ≤ ai, bi ≤ N
  • 1 ≤ pi ≤ 1 000 000 000

서브태스크

번호배점제한
112

N ≤ 200

225

N ≤ 5000

316

pi = 1 for all i

447

No additional constraints

예제 입력 1

5 4
1 2 1
1 3 2
1 4 1
2 4 1

예제 출력 1

4

Picking routes 1–2, 1–3, 1–4 would give a profit of 4 euros per month and this is the correct answer. One can select routes 1–2, 1–4, 2–4 as well, but profit would then be smaller – 3.

예제 입력 2

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

예제 출력 2

21

예제 입력 3

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

예제 출력 3

40

채점 및 기타 정보

  • 예제는 채점하지 않는다.