CF875F.Royal Questions
省选/NOI-
通过率:0%
时间限制:1.50s
内存限制:512MB
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 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.
在一座中世纪王国中,经济危机正肆虐蔓延:牛奶价格暴跌,各项经济指标日日恶化,国库中的金钱不翼而飞。为扭转局势,查尔斯·阳光脸国王决定让他的 n 位王子儿子迎娶嫁妆尽可能丰厚的新娘。
为遴选合适人选,国王向邻近诸国发出请求;不久之后,数支使团携 m 位待字闺中的公主抵达王宫。接待宾客时,国王卡尔得知:第 i 位公主的嫁妆为 wi 枚金币。
尽管故事发生在中世纪,社会上却已广泛流行进步思想——即绝不可强迫一位公主嫁给其不喜欢的王子。因此,每位公主均可自主选择两位王子,她只愿嫁给这两人中的某一位。而王子们则没那么幸运:在择偶一事上,他们必须服从父王的旨意。
在已知每位公主的嫁妆数额及其偏好(即各自可接受的两位王子)的前提下,查尔斯国王希望安排婚礼,使得所有成婚王子所迎娶新娘的嫁妆总额最大化。注意:并非必须让所有王子或所有公主都结婚;每位王子最多只能迎娶一位公主,反之亦然,每位公主最多只能嫁给一位王子。
请帮助国王以对国库最有利的方式为其诸子安排婚事。
输入格式
The first line contains two integers n, m (2 ≤ n ≤ 200 000, 1 ≤ m ≤ 200 000) — 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 ≤ 10 000) — number of princes, which i-th princess is ready to marry and the value of her dowry.
第一行包含两个整数 n、m(2 ≤ n ≤ 200000,1 ≤ m ≤ 200000)—— 分别表示王子与公主的数量。
接下来的 m 行中,每行包含三个整数 ai、bi、wi(1 ≤ ai,bi ≤ n,ai = bi,1 ≤ wi ≤ 10000)—— 表示第 i 位公主愿意嫁给的两位王子的编号,以及她的嫁妆价值。
输出格式
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
输入解题思路,AI测评打分。不知道怎么写?