#K92667. Check if Linked List is Empty
Check if Linked List is Empty
Check if Linked List is Empty
You are given a linked list containing elements \(1, 2, \dots, n\). In addition, you are provided with \(m\) removal operations. Each operation is given by a line containing an integer \(k\) followed by \(k\) distinct elements to be removed from the list.
After performing all removal operations, your task is to determine whether the linked list is empty. If all elements have been removed, print YES
; otherwise, print NO
.
Note: Even if an element is attempted to be removed multiple times, it only counts once.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two space-separated integers \(n\) and \(m\), where \(n\) is the total number of elements in the linked list and \(m\) is the number of removal operations.
- The next \(m\) lines each represent one operation. Each operation begins with an integer \(k\), followed by \(k\) space-separated integers indicating the elements to remove in that operation.
outputFormat
Output one line to the standard output (stdout):
YES
if the linked list is empty after all removal operations.NO
if there is at least one element remaining in the list.
5 3
2 1 3
1 2
2 4 5
YES
</p>