#C11706. Warehouse Shipment Query

    ID: 41052 Type: Default 1000ms 256MiB

Warehouse Shipment Query

Warehouse Shipment Query

You are given a warehouse system that manages shipments. Each shipment has a unique identifier and a set of attributes describing it. Your task is to implement a system that supports two operations:

  • Insertion: Insert a shipment with an identifier and a list of attributes.
  • Query: Given a set of attributes, determine whether there exists a shipment such that the shipment's attribute set contains all queried attributes (i.e. if the query set \(Q\) and the shipment's attribute set \(A\) then check whether \(Q \subseteq A\)).

The input begins with two integers \(n\) and \(m\), where \(n\) is the number of initial shipments and \(m\) is the number of queries. The following \(n\) lines each provide shipment details, starting with the shipment's unique identifier, followed by its attributes separated by spaces. Then \(m\) lines follow, each containing space-separated attributes to query.

For each query, output YES if there exists at least one shipment that contains all of the queried attributes and NO otherwise.

inputFormat

The input is read from standard input and is structured as follows:

 n m
 shipment_1
 shipment_2
 ...
 shipment_n
 query_1
 query_2
 ...
 query_m

Where:

  • The first line contains two integers \(n\) and \(m\).
  • Each of the next \(n\) lines contains the shipment details. The first token is the unique shipment identifier, followed by one or more attributes.
  • Each of the following \(m\) lines contains a query represented by a list of space-separated attributes.

outputFormat

For each query, output a single line containing either YES or NO. YES indicates that there exists at least one shipment whose attributes includes all the queried attributes; otherwise, output NO.

## sample
0 3

apple
banana cherry
grape
NO

NO NO

</p>