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賬號,即可開始考試

? 2025. All Rights Reserved. 滬ICP備2023009024號-1