#C5860. Unique Warehouse Delivery
Unique Warehouse Delivery
Unique Warehouse Delivery
You are given a set of warehouse-item pairs and a sequence of delivery orders. Each pair indicates that a specific item is stored in a specific warehouse. For each delivery order, you must deliver the requested item by visiting the corresponding warehouse. However, you are allowed to visit each warehouse at most once.
Formally, let \(W(i)\) denote the warehouse that stores item \(i\). Given a sequence of delivery orders \(a_1, a_2, \dots, a_m\), the delivery is possible if and only if all warehouses \(W(a_1), W(a_2), \dots, W(a_m)\) are distinct. Output Yes
if the sequence of deliveries can be completed without revisiting any warehouse, otherwise output No
.
inputFormat
The input is given via standard input and has the following format:
- The first line contains an integer \(n\), the number of warehouse-item pairs.
- The next \(n\) lines each contain two integers: the warehouse id and the item id.
- The following line contains an integer \(m\), the number of delivery orders.
- The last line contains \(m\) integers, representing the sequence of delivery orders (each integer is an item id).
outputFormat
Output a single line via standard output containing either Yes
or No
(without quotes), indicating whether it is possible to complete all deliveries without visiting any warehouse more than once.
3
1 2
2 3
3 4
4
2 3 4 2
No