当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6141:I am your Father!

题目描述
> Darth Vader: "Obi-Wan never told you what happened to your father."
>
> Luke Skywalker: "He told me enough! He told me you killed him!"
>
> Darth Vader: "No, I am your father."
>
> — Vader and Luke, on Cloud City

A list of $n$ force-aware males numbered $1$ through $n$ were found. They are the chosen ones that will bring balance to the force. Being listed at the first place, Anakin Skywalker is the ancestor of all rest $n-1$ persons.

Interestingly, everyone else claims he is the father of some others, causing serious troubles. Fortunately, you found the list also comes with these claims and their likelihood. Your task is to find the true father of Nikana, the last one in the list (numbered $n$).

There are $m$ claims in the list. The $i$-th claim consists of three integers: $x_i$, $y_i$, and $w_i$, indicating that the $x_i$-th person claims he is the father of the $y_i$-th person, with a likelihood of $w_i$.

Your task is to find a global assignment that assigns each person (except Anakin Skywalker) to someone in the list, i.e., find $f(u)$ such that:

1. Everyone is assigned a father, i.e., $f(u)\in\{1,2,\ldots,n\}$ for all $u\in\{2,3,\ldots,n\}$.
2. Each one's assigned father claims their relationship, i.e., for all $u$, there exists a claim $i$ in the claims such that $f(u) = x_i\land u=y_i$.
3. Nobody is an ancestor of himself in the assignment, directly or indirectly.
4. The assignment maximizes the sum of the likelihood of the father-and-son relationships, i.e., $W=\sum_{i} w_i$ if $f(u)=x_i\land u=y_i$ is in the assignment.

You should find the father of Nikana (the person numbered $n$) in such an optimized assignment. If multiple assignments have the same optimal likelihood $W$, you should find the assignment that minimizes the lexical number of his father, i.e., minimizes $f(n)$ at the same time has an optimal assignment likelihood $W$. That makes Nikana closer to Anakin Skywalker.
输入解释
There are multiple test cases in the input file. The first line of the input gives the number of test cases $T$, then followed by $T$ test cases.

The first line of a test case contains $n$ ($1\le n\le 10^3$) and $m$ ($m\le 10^4$), the number of persons and the number of claims, respectively.

Then $m$ lines follows. The $i$-th line contains three integers: $x_i$, $y_i$, and $w_i$ indicating the claimed father, son, and likelihood. $1\le w_i\le 100$ is guaranteed. Nobody will claim someone as his son twice.
输出解释
For each test case, output one line containing two space-separated integers, the maximum likelihood $W$ and the father of Nikana.
输入样例
2
3 3
1 2 10
1 3 10
2 3 10
3 3
1 2 10
1 3 10
2 3 11
输出样例
20 1
21 2
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6141

最后修改于 2020-10-25T23:28:42+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)