Graduation Table
InterviewTime limit1sMemory limit1024 MB
Given friend pairs with bribe values at a circular table where each person has at most two friends, choose which pairs to seat together to maximize total bribes.
Problem
You have been asked to organize the computing science graduation banquet. There are people attending, and they must all be seated around a large circular table. Some pairs of attendees are friends and want to sit next to each other. Since all attendees are computing science majors, none has more than 2 friends.
These pairs have privately asked for seats together and offered you a bribe if you fulfill the request. You care about your integrity, but you also care about money, so you will only accept a bribe if you can fulfill that pair's request. You want to maximize the total money you earn by accepting the most profitable set of bribes.
Input
The first line contains two integers () and (), the number of attendees and the number of seating requests. Then lines follow, each with three integers , (), and (). This means attendees and will pay dollars to sit next to each other.
Each pair submits at most one request, and each attendee appears in at most two requests.
Output
Print the maximum number of dollars you can earn over all possible seating arrangements.