Graduation Table

시간 제한1초메모리 제한1024 MB

요약
친구가 각각 최대 두 개의 요청을 낸 상황에서, 원탁 한 바퀴에 담을 수 있는 가장 이익이 큰 간선 집합을 고른다.
난이도

보통10점 중 7점

유형
그래프, 동적 계획법, 그리디
정답자
아직 제출이 없습니다

문제

You have been asked to organize the computing science graduation banquet. There are nn people attending the banquet, and they must all be seated around a large circular table. As it turns out, some pairs of attendees are friends and wish to sit next to each other. Thankfully, since all the attendees are computing science majors, none have more than 2 friends.

While there is no official way to request seating arrangements, these pairs have come to you privately and offered you a bribe if you fulfill their request. You care about your integrity, but you also care about money, so you will only accept bribes if you can fulfill the pair’s request. You wish to maximize the amount of money you can earn by accepting the most profitable set of bribes.

입력

The first line of input contains two integers NN (1≤N≤50001 \leq N \leq 5000) and MM (0≤M≤N0 \leq M \leq N), indicating the number of banquet attendees and the number of seating requests, respectively. Then MM lines follow, each containing three integers uu, vv (1≤u<v≤n1 \leq u < v \leq n), and cc (1≤c≤1081 \leq c \leq 10^8) indicating that attendees uu and vv are willing to pay you cc dollars to sit next to each other.

It is guaranteed that any pair will submit at most one request to sit with each other, and each individual attendee will appear in at most two requests.

출력

Output the maximum number of dollars you can make over all possible seating arrangements.

예제2

  1. 예제 1

    입력
    3 3
    1 2 1
    2 3 2
    1 3 3
    
    예상 출력
    6
    
  2. 예제 2

    입력
    5 4
    1 2 1
    2 3 2
    1 3 3
    4 5 4
    
    예상 출력
    9