CF1019E.Raining season
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
By the year 3018, Summer Informatics School has greatly grown. Hotel «Berendeetronik» has been chosen as a location of the school. The camp consists of n houses with n−1 pathways between them. It is possible to reach every house from each other using the pathways.
Everything had been perfect until the rains started. The weather forecast promises that rains will continue for m days. A special squad of teachers was able to measure that the i-th pathway, connecting houses ui and vi, before the rain could be passed in bi seconds. Unfortunately, the rain erodes the roads, so with every day the time to pass the road will increase by ai seconds. In other words, on the t-th (from zero) day after the start of the rain, it will take ai⋅t+bi seconds to pass through this road.
Unfortunately, despite all the efforts of teachers, even in the year 3018 not all the students are in their houses by midnight. As by midnight all students have to go to bed, it is important to find the maximal time between all the pairs of houses for each day, so every student would know the time when he has to run to his house.
Find all the maximal times of paths between every pairs of houses after t=0, t=1, ..., t=m−1 days.
到3018年,暑期信息学学校已大幅扩张。酒店「贝伦迪特罗尼克」被选定为该校的举办地点。营地由 n 座房屋组成,房屋之间共有 n−1 条通道相连,且任意两座房屋之间均可通过这些通道相互到达。
一切本都十分完美,直到大雨开始降临。天气预报显示,降雨将持续 m 天。一支由教师组成的特别小队成功测得:第 i 条通道(连接房屋 ui 和 vi)在降雨前可通过时间为 bi 秒。不幸的是,雨水不断侵蚀道路,导致每过一天,通过该道路所需时间增加 ai 秒。换言之,在降雨开始后的第 t 天(t 从 0 开始计数),通过该道路所需时间为 ai⋅t+bi 秒。
遗憾的是,尽管教师们竭尽全力,即使在3018年,也并非所有学生都能在午夜前回到自己的房屋。而根据规定,所有学生必须于午夜就寝,因此,每天计算出所有房屋对之间的最长路径时间至关重要,以便每位学生都能知晓自己最迟需何时奔向自己的房屋。
请计算在 t=0,1,…,m−1 天(即降雨开始后第 0 至第 m−1 天)时,所有房屋对之间路径的最大耗时。
输入格式
In the first line you are given two integers n and m — the number of houses in the camp and the number of raining days (1≤n≤100000; 1≤m≤1000000).
In the next n−1 lines you are given the integers ui, vi, ai, bi — description of pathways (1≤ui,vi≤n; 0≤ai≤105; 0≤bi≤109). i-th pathway connects houses ui and vi, and in day t requires ai⋅t+bi seconds to pass through.
It is guaranteed that every two houses are connected by a sequence of pathways.
第一行给出两个整数 n 和 m —— 分别表示营地中的房屋数量和降雨天数(1≤n≤100000;1≤m≤1000000)。
接下来的 n−1 行中,每行给出四个整数 ui、vi、ai、bi —— 描述一条路径(1≤ui,vi≤n;0≤ai≤105;0≤bi≤109)。第 i 条路径连接房屋 ui 和 vi,且在第 t 天通过该路径所需时间为 ai⋅t+bi 秒。
保证任意两座房屋之间均存在由若干路径构成的连通序列。
输出格式
Print m integers — the lengths of the longest path in the camp after a t=0,t=1,…,t=m−1 days after the start of the rain.
输出 m 个整数——分别表示从开始下雨起经过 t=0,t=1,…,t=m−1 天后营地中最长路径的长度。
输入输出样例
输入#1
5 10 1 2 0 100 1 3 0 100 1 4 10 80 1 5 20 0
输出#1
200 200 200 210 220 230 260 290 320 350
说明/提示
Let's consider the first example.
In the first three days (0≤t≤2) the longest path is between 2nd and 3rd houses, and its length is equal to 100+100=200 seconds.
In the third day (t=2) the road between houses 1 and 4 has length 100 and keeps increasing. So, in days t=2,3,4,5 the longest path is between vertices 4 and (1 or 2), and has length 180+10t. Notice, that in the day t=2 there are three pathways with length 100, so there are three maximal paths of equal length.
In the sixth day (t=5) pathway between first and fifth houses get length 100. So in every day with t=5 and further the longest path is between houses 4 and 5 and has length 80+30t.
我们来考虑第一个例子。
在前三天(0≤t≤2)中,最长路径位于第 2 号与第 3 号房屋之间,其长度为 100+100=200 秒。
在第三天(t=2),1 号与 4 号房屋之间的道路长度为 100,且持续增长。因此,在 t=2,3,4,5 这几天中,最长路径位于顶点 4 与(顶点 1 或顶点 2)之间,其长度为 180+10t。注意,在第 t=2 天,共有三条长度为 100 的路径,因此存在三条等长的最长路径。
在第六天(t=5),1 号与 5 号房屋之间的路径长度达到 100。因此,从第 t=5 天起,每一天的最长路径均位于 4 号与 5 号房屋之间,其长度为 80+30t。
输入解题思路,AI测评打分。不知道怎么写?