CF875F.Royal Questions

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In a medieval kingdom, the economic crisis is raging. Milk drops fall, Economic indicators are deteriorating every day, money from the treasury disappear. To remedy the situation, King Charles Sunnyface decided make his nn sons-princes marry the brides with as big dowry as possible.

In search of candidates, the king asked neighboring kingdoms, and after a while several delegations arrived with mm unmarried princesses. Receiving guests, Karl learned that the dowry of the ii th princess is wiw_{i} of golden coins.

Although the action takes place in the Middle Ages, progressive ideas are widespread in society, according to which no one can force a princess to marry a prince whom she does not like. Therefore, each princess has an opportunity to choose two princes, for each of which she is ready to become a wife. The princes were less fortunate, they will obey the will of their father in the matter of choosing a bride.

Knowing the value of the dowry and the preferences of each princess, Charles wants to play weddings in such a way that the total dowry of the brides of all his sons would be as great as possible. At the same time to marry all the princes or princesses is not necessary. Each prince can marry no more than one princess, and vice versa, each princess can marry no more than one prince.

Help the king to organize the marriage of his sons in the most profitable way for the treasury.

输入格式

The first line contains two integers nn , mm ( 2<=n<=2000002<=n<=200000 , 1<=m<=2000001<=m<=200000 ) — number of princes and princesses respectively.

Each of following mm lines contains three integers aia_{i} , bib_{i} , wiw_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n , aibia_{i}≠b_{i} , 1<=wi<=100001<=w_{i}<=10000 ) — number of princes, which ii -th princess is ready to marry and the value of her dowry.

输出格式

Print the only integer — the maximum number of gold coins that a king can get by playing the right weddings.

输入输出样例

  • 输入#1

    2 3
    1 2 5
    1 2 1
    2 1 10
    

    输出#1

    15
  • 输入#2

    3 2
    1 2 10
    3 2 20
    

    输出#2

    30
首页