Forests
InterviewTime limit1sMemory limit128 MB
Count how many distinct nonempty sets of trees appear among the (person, tree) pairs; people who heard nothing are excluded.
- Level
Easy3 of 10
- Topics
- Hash map, Sorting, Array, Implementation
- Solved
- No attempts yet
Problem
If a tree falls in the forest, and there is nobody there to hear it, does it make a sound? This classic conundrum was coined by George Berkeley (1685-1753), the bishop and influential Irish philosopher whose primary philosophical achievement is the advancement of what came to be called subjective idealism. He wrote a number of works, of which the most widely read are A Treatise Concerning the Principles of Human Knowledge (1710) and Three Dialogues between Hylas and Philonous (1713) — Philonous, the "lover of the mind," representing Berkeley himself.
Input
A forest contains trees, numbered from to , and people, numbered from to .
The first line contains two integers: the number of people and the number of trees (both less than ). Each of the following lines contains a pair of integers and , indicating that person has heard tree fall.
Different people may hold different opinions about which trees, according to Berkeley, have made a sound.
Output
Print a single integer: the number of different opinions represented in the input. Two people hold the same opinion only if they have heard exactly the same set of trees fall.
A person who is never mentioned in any pair has heard no trees fall and expresses no opinion, so they are not counted. In particular, if the input contains no pairs, print .