#P2712. Squirrel Heist
Squirrel Heist
Squirrel Heist
Problem Statement: In a food store, there are (n) cameras. Each camera is fixed at a specific position and monitors a designated location. Both the cameras and the positions they monitor are assigned unique numbers from a unified sequence. A camera can be smashed only if its own position is not monitored by any other camera. The mischievous squirrels plan to destroy cameras in order to avoid leaving any evidence of their heist. Your task is to determine whether all cameras can be smashed. If yes, output (YES); if not, output the number of cameras that remain unsmashed (i.e. those still being monitored by at least one other camera).
inputFormat
Input Format: The first line contains an integer (n) ((1 \le n \le 10^5)) representing the number of cameras. Each of the next (n) lines contains two integers (a) and (b) ((1 \le a, b \le 10^9)), where (a) is the position of a camera and (b) is the position it monitors.
outputFormat
Output Format: If all cameras can be smashed, output (YES). Otherwise, output a single integer denoting the number of cameras that cannot be smashed because their position is monitored by some other camera.
sample
3
1 2
2 3
3 1
3