AT_scpc2026_div3_h.Cramming

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

An exam is approaching! queued_q has TT hours left until the exam, and the exam covers NN topics. Studying each topic basically takes AA hours. queued_q wants to study as many topics as possible while keeping the total study time at most TT.

Some topics are related to one another. If queued_q has previously studied topics related to the topic to be studied next, that topic becomes easier to study. The relationships between exam topics can be represented as a tree with NN vertices and N−1N-1 edges. The ii-th edge of the tree means that topic uiu_i and topic viv_i are directly related to each other. When studying topic ii, if kk topics adjacent to ii have already been studied, the actual time required to study topic ii is max⁡(1,A−B×k)\max(1, A - B \times k). In other words, each additional adjacent topic already studied decreases the study time by BB, but at least 11 hour must be spent.

queued_q wants to choose the topics to study and their order appropriately so as to study as many topics as possible. Find the maximum number of topics KK that queued_q can study within TT hours, the minimum time MM required to study KK topics, and an order that achieves them.

考试即将到来!queued_q 距离考试还有 TT 小时,而考试涵盖 NN 个知识点。学习每个知识点通常需要 AA 小时。queued_q 希望在总学习时间不超过 TT 小时的前提下,尽可能多地学习知识点。

某些知识点之间存在关联。若 queued_q 在学习下一个知识点之前,已学习过与该知识点相关联的知识点,则该知识点的学习难度会降低。各考试知识点之间的关联关系可表示为一棵含 NN 个顶点和 N−1N-1 条边的树。树的第 ii 条边表示知识点 uiu_i 与知识点 viv_i 直接相关。当学习知识点 ii 时,若其邻接知识点中已有 kk 个被学习过,则实际所需学习时间为 max⁡(1,A−B×k)\max(1, A - B \times k)。换言之,每多一个已被学习的邻接知识点,学习时间就减少 BB 小时,但至少需花费 11 小时。

queued_q 希望恰当地选择所学知识点及其学习顺序,以最大化所学知识点数量。请找出在 TT 小时内最多能学习的知识点数量 KK、学习这 KK 个知识点所需的最少时间 MM,以及达成该目标的一种学习顺序。

输入格式

The input is given from Standard Input in the following format:

NN TT AA BB
u1u_1 v1v_1
u2u_2 v2v_2
⋮\vdots
uN−1u_{N-1} vN−1v_{N-1}

输入从标准输入中按以下格式给出:

NN TT AA BB
u1u_1 v1v_1
u2u_2 v2v_2
⋮\vdots
uN−1u_{N-1} vN−1v_{N-1}

输出格式

On the first line, output the maximum number of topics KK that queued_q can study and the minimum time MM required to study KK topics, separated by a space.

On the second line, output an optimal order for studying KK topics, separated by spaces. If there are multiple optimal orders, output any one of them. If K=0K=0, note that the second line should be empty.

第一行输出 queued_q 最多可以学习的主题数 KK 以及学习这 KK 个主题所需的最少时间 MM,两者之间用空格分隔。

第二行输出一个学习这 KK 个主题的最优顺序,各主题编号之间用空格分隔。若存在多个最优顺序,输出任意一种即可。若 K=0K=0,则第二行应为空行。

输入输出样例

  • 输入#1

    2 1 1 0
    1 2

    输出#1

    1 1
    1
  • 输入#2

    4 0 1 1
    1 2
    1 3
    1 4

    输出#2

    0 0

说明/提示

表示言語

/ /

Constraints

  • 1≤N≤200 0001 \leq N \leq 200\,000
  • 0≤T≤1090 \leq T \leq 10^9
  • 1≤A≤1091 \leq A \leq 10^9
  • 0≤B≤A0 \leq B \leq A
  • 1≤ui<vi≤N1 \leq u_i < v_i \leq N
  • The given relationships always form a tree.
  • All given numbers are integers.

表示语言

/ /

约束条件

  • 1≤N≤200 0001 \leq N \leq 200\,000
  • 0≤T≤1090 \leq T \leq 10^9
  • 1≤A≤1091 \leq A \leq 10^9
  • 0≤B≤A0 \leq B \leq A
  • 1≤ui<vi≤N1 \leq u_i < v_i \leq N
  • 给定的关系始终构成一棵树。
  • 所有给定的数均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页