P2712 Cameras
Description
There are $n$ cameras in a grocery store. These cameras are clumsy and can only capture fixed positions. A group of bold squirrels wants to rob the store. To avoid being recorded, the first thing they plan to do is to destroy the cameras.
To make it easier to destroy the cameras, the squirrels assign a unified set of IDs to all cameras and to all positions that any camera can monitor. A camera can be destroyed if and only if the position where it is located is not monitored by any other camera.
Your task is to determine whether it is possible to destroy all cameras. If not, output the number of cameras that remain undestroyed.
Input Format
The first line contains an integer $n$, the number of cameras.
Lines $2$ to $n+1$ describe the cameras. Each line contains the camera’s position $x$, the number of positions $m$ it can monitor, followed by $m$ numbers $y$ that are the positions this camera can monitor (once this camera is destroyed, these positions are naturally no longer monitored).
Output Format
If it is possible to destroy all cameras, output $\texttt{YES}$; otherwise, output the number of cameras that remain undestroyed (without quotes).
Explanation/Hint
Constraints
- $1 \leq n \leq 100$.
- $0 \leq m \leq 100$.
- $0 \leq x, y \leq 500$.
Translated by ChatGPT 5