「已注销」 2024-10-02 13:57 采纳率: 50%
浏览 7
已结题

找呀,找呀,找翻译,请个人来翻个译😒

描述

A trader would like to make a business of travelling between cities, moving goods from one
city to another in exchange for a profit. There are N cities labelled 1, . . . , N and N − 1
roads. Each road joins two cities and takes one day to traverse. It is possible to reach any
city from any other city using these roads.
The i-th city can give a profit of pi
if the trader is currently in that city and chooses to
do business in that city, but this profit may only be obtained once. The trader starts by
doing business in city 1 and wants to travel along the roads, visiting cities to maximize their
total profit. However, the trader’s boss will get unhappy and lay off the trader as soon as
the trader goes more than K days in a row without increasing their total profit. Note that
the trader will take only one day to move between adjacent cities, regardless of whether the
trader does business in either city. We would like to know the maximum profit the trader
can make under this condition and a route that obtains this profit.
输入描述
```c++
The first line of input contains two space-separated integers N and K.
The next N − 1 lines of input each contain two space-separated integers ui and vi (1 ≤
ui
, vi ≤ N, ui ̸= vi), describing a road.
The last line of input contains N integers p1, . . . , pN (1pi109
), the profits given by
choosing to do business in the corresponding city.

输出描述

On the first line, output the maximum possible total profit.
On the second line, output M (1 ≤ M ≤ N), the number of cities the trader does business
in on an optimal route.
On the third line, output M space-separated integers x1, . . . , xM, the cities the trader does
business in on an optimal route in order, starting with x1 = 1.
If there are multiple possible correct outputs, any correct output will be accepted.




样例输入 1 

4 1
1 2
1 3
2 4
3 1 4 1
样例输出 1 

7
2
1 3
样例输入 2 

5 2
1 2
1 3
2 4
2 5
3 1 4 1 5
样例输出 2 

14
5
1 4 5 2 3
提示

数据范围与提示


Explanation of Output for Sample Input 1
On day 1, the trader starts by doing business in city 1, making a profit of 3.
On day 2, the trader moves to city 3 and does business there, making a profit of 4.
At this point, the trader cannot reach another city in which they have not done business
before getting laid off, so their total profit is 7.

Explanation of Output for Sample Input 2
The trader can make a profit in every city by visiting them in the order 1, 2, 4, 2, 5, 2, 1, 3.
Note that the trader strategically delays doing business in city 2 to ensure they do not go
more than 2 days without making a profit.

  • 写回答

2条回答 默认 最新

  • 铭渊老黄 新星创作者: Python技术领域 2024-10-02 15:02
    关注
    🕒下午好,题主!目前:🟢[在线]
    📢参考GPT-4o mini 模型、由清水白石008整理提供!
    📣今日金句:“成功的秘诀在于抓住每一个机会。”** — 亚里士多德
    

    问题描述

    一个商人想要通过在城市之间旅行,搬运货物来赚取利润。有 N 个城市标记为 1 到 N,并且有 N-1 条道路。每条道路连接两个城市,花费一天时间穿越。可以通过这些道路从任何一个城市到达任何其他城市。

    第 i 个城市可以给出利润 pi,如果商人当前在该城市并选择在该城市做生意,但这种利润只能获得一次。商人从城市 1 开始做生意,并希望沿着道路旅行,访问城市以最大化他们的总利润。然而,如果商人连续超过 K 天没有增加总利润,老板就会不高兴并解雇商人。注意,商人从一个相邻城市移动到另一个相邻城市只需要一天时间,无论商人在任何一个城市是否做生意。我们想知道在这种情况下商人可以获得的最大利润以及获得该利润的路线。

    输入描述

    第一行输入包含两个空格分隔的整数 N 和 K。
    接下来的 N-1 行输入每行包含两个空格分隔的整数 ui 和 vi (1 ≤ ui, vi ≤ N, ui ≠ vi),描述一条道路。
    最后一行输入包含 N 个整数 p1, ..., pN (1 ≤ pi ≤ 10^9),表示选择在相应城市做生意所获得的利润。

    输出描述

    第一行输出最大可能的总利润。
    第二行输出 M (1 ≤ M ≤ N),表示商人在最佳路线中做生意的城市数量。
    第三行输出 M 个空格分隔的整数 x1, ..., xM,表示商人在最佳路线中按顺序做生意的城市,起始城市为 x1 = 1。

    样例输入 1

    4 1
    1 2
    1 3
    2 4
    3 1 4 1
    

    样例输出 1

    7
    2
    1 3
    

    样例输入 2

    5 2
    1 2
    1 3
    2 4
    2 5
    3 1 4 1 5
    

    样例输出 2

    14
    5
    1 4 5 2 3
    

    提示

    样例输出 1 解释

    第 1 天,商人在城市 1 开始做生意,赚取 3 的利润。
    第 2 天,商人移动到城市 3 并在那里做生意,赚取 4 的利润。
    此时,商人无法在不被解雇的情况下到达另一个未做生意的城市,因此总利润为 7。

    样例输出 2 解释

    商人可以通过按顺序访问城市 1, 2, 4, 2, 5, 2, 1, 3 在每个城市赚取利润。
    注意,商人策略性地延迟在城市 2 做生意,以确保他们不会连续超过 2 天没有赚取利润。

    希望这个翻译能帮助你理解问题。如果有任何疑问或需要进一步的帮助,请随时告诉我。😊

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月10日
  • 已采纳回答 10月2日
  • 创建了问题 10月2日