#P1525. [NOIP 2010 提高组] 关押罪犯

    ID: 516 远端评测题 1000ms 125MiB 尝试: 1 已通过: 1 难度: 6 上传者: 标签>图论贪心2010并查集NOIp 提高组排序二分图

[NOIP 2010 提高组] 关押罪犯

Description

City S currently has two prisons, holding NN criminals numbered from 11 to NN. Their relationships are highly discordant. Many pairs of criminals have long-standing grudges and may break into conflict whenever conditions allow. We use the “resentment value” (a positive integer) to represent the hatred between two criminals; the larger the resentment value, the deeper their grudge. If two criminals with resentment value cc are held in the same prison, they will clash and cause a conflict event with impact cc.

At the end of each year, the police department sorts all conflict events in the prisons by impact from large to small, and submits the list to Mayor Z of City S. The busy Mayor Z will only look at the impact of the first event in the list. If the impact is severe, he may consider replacing the police chief.

After carefully reviewing the conflicts among the NN criminals, the police chief feels great pressure. He plans to reassign the criminals between the two prisons to keep the impact of conflict events low, thereby protecting his position. Assume that if two criminals held in the same prison have a grudge, they will certainly clash at some point during the year.

How should the criminals be assigned to minimize the impact of the conflict event that Mayor Z sees? What is this minimum value?

Input Format

A single space separates two numbers in a line. The first line contains two positive integers N,MN, M, representing the number of criminals and the number of pairs with grudges, respectively. Each of the next MM lines contains three positive integers aj,bj,cja_j, b_j, c_j, indicating that criminals aja_j and bjb_j have a grudge with resentment value cjc_j. It is guaranteed that 1aj<bjN1 \le a_j < b_j \leq N, 0<cj1090 < c_j \leq 10^9, and each pair of criminals appears at most once.

Output Format

Output a single line: the impact of the conflict event that Mayor Z sees. If no conflict occurs in the prisons this year, output 0.

4 6
1 4 2534
2 3 3512
1 2 28351
1 3 6618
2 4 1805
3 4 12884
3512

Hint

Input-output sample explanation:

The resentment values between criminals are shown in the left figure below. The right figure shows an assignment of criminals; the impact of the conflict event that the mayor sees is 35123512 (caused by criminals 22 and 33). No other assignment is better than this one.

Constraints

  • For 30%30\% of the testdata, N15N \leq 15.
  • For 70%70\% of the testdata, N2000N \leq 2000, M50000M \leq 50000.
  • For 100%100\% of the testdata, N20000N \leq 20000, M100000M \leq 100000.

Translated by ChatGPT 5