CIW '26 P1 - Shopping Mall
View as PDFCanadian Informatics Workshop 2026: Day 1, Problem 1
It's Black Friday! Linx is at the mall with her friends, hoping to get
some good deals. Linx has a shopping list of items, labeled 1 to
that she wants to buy.
The mall contains locations, each labeled with a number
from
to
.
A location labeled
with
is a shop that sells item
.
A location labeled
denotes an entrance to the mall.
A location labeled
is a shop that does not sell any of the
items that Linx wants.
The locations are connected by bidirectional paths, each taking 1
unit of time to traverse, and it is guaranteed that there is a route
between any two locations.
Since Linx is a bit of a perfectionist, she wants to purchase all
items in ascending order, from item 1 to item
. The mall may have
multiple entrances, which are all equally accessible from the bus stop,
so Linx can start her shopping spree at any entrance (denoted by
). She also doesn't mind visiting a shop more than once.
Input Specification
The first line of input contains three space-separated integers ,
, and
(
).
The next line contains space-separated integers,
(
), indicating the label for each location. It is
guaranteed that each number from
to
appears at least once.
The next lines each contain two space-separated integers,
and
, indicating that there is a
path between the
-th and
-th location, which takes 1 unit of
time to traverse. The following table shows how the available 25 marks
are distributed:
| Marks Awarded | Bounds on |
Bounds on |
Additional Constraints |
|---|---|---|---|
| 3 marks | There is only one entrance (i.e. |
||
| 5 marks | There is only one entrance (i.e. |
||
| 2 marks | None | ||
| 4 marks | There is only one shop of each type. That is, |
||
| 3 marks | None | ||
| 8 marks | None |
Output Specification
On a single line, output the least amount of time Linx must take to
purchase all items on her shopping list. It can be shown that this
is always possible.
Sample Input 1
5 4 3
0 1 3 2 2
1 2
2 3
3 4
4 5
Sample Output 1
4
Explanation for Sample Output 1
Linx starts at the entrance at location 1. She then travels to location
2 and purchases item 1 there. Next, she travels to location 3 but does
not purchase anything. Then, she travels to location 4 and purchases
item 2 there. Finally, Linx returns to location 3 to purchase item 3.
The total time taken is 4 units, following the location path
.
Sample Input 2
7 8 3
3 -1 0 1 0 2 1
3 4
3 7
3 1
5 7
6 7
7 2
7 1
1 2
Sample Output 2
4
Explanation for Sample Output 2
An example of the shortest path that Linx can take is
.
That is, Linx starts at the entrance at location 3. She then travels to
location 7 and purchases item 1. Next, she travels to location 6 and
purchases item 2. Then, she returns to location 7 but does not purchase
anything. Finally, Linx travels to location 1 and purchases item 3.
Comments