2023-2024赛季的USACO考试已于12月18日正式结束,晋级赛的最新试题也已经公布。近日,USACO官方公布了2023-2024赛季首场月赛的晋级分数线。如果没有晋级,12月可以当做一个练手+熟悉赛制的环节,1、2月的月赛持续发力,USACO可以重复挑战。
今天给大家分享金级试题和解析,参赛的同学来看看解题思路,没参赛的同学来看看难度如何?
USACO 2023年12月金级第二题
Bessie is going on a trip in Cowland, which has N (2≤N≤2⋅105) towns numbered from 1 to N and M (1≤M≤4⋅105) one-way roads. The ith road runs from town ai
to town bi and has label li (1≤ai , bi≤N, 1≤li≤109).
A trip of length k starting at town x0 is a sequence of towns x0,x1,…,xk, such that there is a road from town xi to town xi+1 for all 0≤i<k. It is guaranteed that there are no trips of infinite length in Cowland, and that no two roads connect the same pair of towns.
For each town, Bessie wants to know the longest possible trip starting at it. For some starting towns, there are multiple longest trips - out of these, she prefers the trip with the lexicographically minimum sequence of road labels. A sequence is lexicographically smaller than another sequence of the same length if, at the first position in which they differ, the first sequence has a smaller element than the second sequence.
Output the length and sum of road labels of Bessie's preferred trip starting at each town.
INPUT FORMAT (pipe stdin):
The first line contains N and M.
The next M lines each contain three integers ai , bi and li, denoting a road from ai
to bi with label li.
OUTPUT FORMAT (pipe stdout):
Output N lines. The ith should contain two space-separated integers, the length and sum of road labels of Bessie's preferred trip starting at town i.
SAMPLE INPUT:
4 5
4 3 10
4 2 10
3 1 10
2 1 10
4 1 10
SAMPLE OUTPUT:
0 0
1 10
1 10
2 20
SAMPLE INPUT:
4 5
4 3 4
4 2 2
3 1 5
2 1 10
4 1 1
SAMPLE OUTPUT:
0 0
1 10
1 5
2 12
In the following explanation, we let represent the road from ai to bi with label li.
There are several trips starting from vertex 4, including and are the longest. These trips each have length 2, and their road label sequences are [4,5]
and [2,10], respectively. [2,10] is the lexicographically smaller sequence, and its sum is 12.
SAMPLE INPUT:
4 5
4 3 2
4 2 2
3 1 5
2 1 10
4 1 1
SAMPLE OUTPUT:
0 0
1 10
1 5
2 7
SAMPLE INPUT:
4 5
4 3 2
4 2 2
3 1 10
2 1 5
4 1 1
SAMPLE OUTPUT:
0 0
1 5
1 10
2 7
SCORING:
Inputs 5-6: All labels are the same.
Inputs 7-8: All labels are distinct.
Inputs 9-10: N,M≤5000
Inputs 11-20: No additional constraints.
Problem credits: Claire Zhang and Spencer Compton
题意:给定一个n个点m条边的有向无环图(DAG),计算从每个点出发最长的链的长度和总长度。如果有多个路径长度都最大,取路径上边长序列字典序最小的链。
题解:
1.40分解法:
拓扑排序,从出度为0的点去搜索。先把每个点深度定为0,尝试用下面的点去更新上面的深度,记录每个点的最长链上的前一个点。当前深度更大的话就更新最长路径,遇到深度相同的时候把之前的链和现在的链暴力比较,就是暴力判断两条链的第一个不同的位置,当前路径字典序更小的话就更新。
2.满分解法:
比较字典序的逻辑改成倍增维护后缀哈希值,每次二分不同位置,去找第一个不同的边比大小。
USACO历年真题及参考书,扫码领取!【翰林提供报名指导服务】USACO历年真题及参考书
2023-2024年USACO活动时间
第一次月赛:2023年12月15日-18日
第二次月赛:2024年1月26日-29日
第三次月赛:2024年2月16日-19日
美国公开赛:2024年3月15日-18日
(中国学生只能参加到公开赛)
集训营:2024年5月23日-6月1日
EGOI:2024年7月21日-27日(荷兰)
IOI:2024年9月1日-8日(埃及)
报名方式:参赛者可随时在官网注册账号,注册。报名,只需在活动时间登陆完成答题即可。
官网地址:usaco.org
提交之后,官网会发送一份邮件到您邮箱,邮件中有账号密码
利用已知的账号于密码,登录USACO账号,即可开始考试
© 2024. All Rights Reserved. 沪ICP备2023009024号-1