#codefestival2016finalc. [codefestival_2016_final_c]Interpretation
[codefestival_2016_final_c]Interpretation
Problem Statement
On a planet far, far away, languages are spoken. They are conveniently numbered through .
For CODE FESTIVAL 20XX held on this planet, participants gathered from all over the planet.
The -th participant can speak languages numbered .
Two participants and can communicate with each other if and only if one of the following conditions is satisfied:
- There exists a language that both and can speak.
- There exists a participant that both and can communicate with.
Determine whether all participants can communicate with all other participants.
Constraints
- The sum of all
- are pairwise distinct.
Partial Score
- points will be awarded for passing the test set satisfying the following: , and The sum of all .
- Additional points will be awarded for passing the test set without additional constraints.
Input
The input is given from Standard Input in the following format:
Output
If all participants can communicate with all other participants, print YES
. Otherwise, print NO
.
Sample Input 1
4 6
3 1 2 3
2 4 2
2 4 6
1 6
Sample Output 1
YES
Any two participants can communicate with each other, as follows:
- Participants and : both can speak language .
- Participants and : both can speak language .
- Participants and : both can communicate with participant .
- Participants and : both can speak language .
- Participants and : both can communicate with participant .
- Participants and : both can communicate with participant .
Note that there can be languages spoken by no participant.
Sample Input 2
4 4
2 1 2
2 1 2
1 3
2 4 3
Sample Output 2
NO
For example, participants and cannot communicate with each other.