In conjunction with the IOI, Pattaya City will host a race: the International Olympiad in Racing (IOR) 2011. As the host, we have to find the best possible course for the race.
In the Pattaya-Chonburi metropolitan area, there are
The IOR has specific regulations that require the course to be a path whose total length is exactly
Your Task
Write a procedure best_path(N,K,H,L)
that takes the following parameters:
– the number of cities. The cities are numbered through . – the required distance for the race course. – a two-dimensional array representing highways. For , highway connects the cities and . – a one-dimensional array representing the lengths of the highways. For , the length of highway is .
You may assume that all values in the array
Your procedure must return the minimum number of highways on a valid race course of length exactly -1
.
Examples
Example 1
Consider the case shown in Figure 1, where
The course can start in city best_path(N,K,H,L)
must return
Example 2
Consider the case shown in Figure 2, where
There is no valid course. In this case, best_path(N,K,H,L)
must return -1
.
Example 3
Consider the case shown in Figure 3, where
One possible course consists of 3 highways: from city best_path(N,K,H,L)
must return
Subtasks
Subtask 1 (9 points)
- The network of highways forms the simplest possible line: For
, highway connects cities and .
Subtask 2 (12 points)
Subtask 3 (22 points)
Subtask 4 (57 points)
Implementation Details
Interface (API)
To be implemented by contestant:
int best_path(int N, int K, int H[][2], int L[]);
Comments
Underrated problem in my opinion, seems harder than somewhat similar 30p Winter Driving (and for my solutions at least, with slightly worse theoretical time complexity).
I would argue that Race is much more straightforwards compared to Winter Driving; you simply apply the right algorithm and you're done (your pick of small-to-large merge or centroid decomposition). Winter Driving involves a little more observation and requires a different property of centroids (not just taking advantage of the path decomposition). If you want to try your hand at some slightly more complicated centroid decomposition problems, https://dmoj.ca/problem/dmopc19c7p6 or https://dmoj.ca/problem/dmpg19g5 might be a good place to start.
Wow just after I commented this, it got changed from 20p to 17p, that's the opposite direction I was suggesting damn. In response to your comment I would argue it is harder due to its higher time complexity (at least so far as I know how to do it)
vs 
for Winter Driving, and that the overlapping parts of the problem are slighter harder to implement for this one.
I'm not sure how problems get their pts rating around here, based on timing it seems like someone just read my comment and decided to spite me (or more charitably genuinely examined its difficulty and came to opposite conclusion of mine).
EDIT: I have been informed there is a reasonable
solution to this so my claim of difficulty is not objective on complexity grounds, and moreover it is apparently routine to investigate pt values after receiving comments, so I am less scandalised by the change to 17p (despite not really agreeing with it based on IOI performance on problem etc.).