LearnPy Hub
← Arena
IntermediateRating 1200

Keys and Rooms

Rooms are numbered 0 … n−1 and only room 0 is unlocked. Each room holds keys to some other rooms. Can you enter every room? Print YES or NO.

Input

n; then n lines, each starting with how many keys the room holds, followed by those room numbers.

Output

YES or NO.

Sample 1

Input
4
1 1
1 2
1 3
0
Output
YES

Sample 2

Input
4
2 1 3
3 3 0 1
1 2
1 0
Output
NO
solution.py
Output appears here
Keys and Rooms · Python Arena problem · LearnPy Hub