304598: CF875F. Royal Questions

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Royal Questions

题意翻译

皇家难题 在一个中世纪时期的的王国,经济危机正在肆虐。牛奶产量下降,经济指标每天都在恶化,财政部的钱在消失。为了补救这种情况,国王Charles Sunnyface决定让他的n个儿子(也就是王子)以尽可能大的嫁妆娶新娘。 为了寻找候选人,国王去了邻近的王国,过了一会儿,几个代表团和m个未婚公主来到了。接到客人后,Charles得知第i个公主的嫁妆是wi个金币。 虽然这件事发生在中世纪,但进步的思想已在社会上普遍存在。所以任何人都不能强迫公主嫁给一个她不喜欢的王子。因此,每个公主都可以选择两个王子,并且都准备好成为一个妻子。王子们就惨一点,他们在选择新娘时只能听从父亲的意愿。 国王Charles 每一位公主的嫁妆价值和喜好,就想以一种使他的所有儿子从新娘获得的嫁妆越多的方式举行婚礼。所有王子或公主不一定都被娶(嫁)。每个王子只能娶一个公主,反之亦然,每个公主只能嫁给一个王子。 现在你要帮助国王编写一个程序,求出组织他儿子的婚姻的最赚钱方式。

题目描述

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 $ n $ 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 $ m $ unmarried princesses. Receiving guests, Karl learned that the dowry of the $ i $ th princess is $ w_{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 $ n $ , $ m $ ( $ 2<=n<=200000 $ , $ 1<=m<=200000 $ ) — number of princes and princesses respectively. Each of following $ m $ lines contains three integers $ a_{i} $ , $ b_{i} $ , $ w_{i} $ ( $ 1<=a_{i},b_{i}<=n $ , $ a_{i}≠b_{i} $ , $ 1<=w_{i}<=10000 $ ) — number of princes, which $ i $ -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

Input

题意翻译

皇家难题 在一个中世纪时期的的王国,经济危机正在肆虐。牛奶产量下降,经济指标每天都在恶化,财政部的钱在消失。为了补救这种情况,国王Charles Sunnyface决定让他的n个儿子(也就是王子)以尽可能大的嫁妆娶新娘。 为了寻找候选人,国王去了邻近的王国,过了一会儿,几个代表团和m个未婚公主来到了。接到客人后,Charles得知第i个公主的嫁妆是wi个金币。 虽然这件事发生在中世纪,但进步的思想已在社会上普遍存在。所以任何人都不能强迫公主嫁给一个她不喜欢的王子。因此,每个公主都可以选择两个王子,并且都准备好成为一个妻子。王子们就惨一点,他们在选择新娘时只能听从父亲的意愿。 国王Charles 每一位公主的嫁妆价值和喜好,就想以一种使他的所有儿子从新娘获得的嫁妆越多的方式举行婚礼。所有王子或公主不一定都被娶(嫁)。每个王子只能娶一个公主,反之亦然,每个公主只能嫁给一个王子。 现在你要帮助国王编写一个程序,求出组织他儿子的婚姻的最赚钱方式。

加入题单

上一题 下一题 算法标签: