luogu#P4906. 小奔关闹钟

小奔关闹钟

Background

Because today is Monday, the alarm rang on time. Since Xiao Ben was too sleepy, he wanted to turn off the alarm clock.

Problem Description

However, the alarm’s circuit is too complicated. There are many switches, and each switch is connected to other switches; those switches are connected to even more switches. Only when all switches are off will the alarm stop ringing (initially, every switch is on). What should he do?

Please help Xiao Ben find the minimum number of switch presses. If the alarm cannot be turned off no matter what, output Change an alarm clock,please!

Input Format

There are N+1N+1 lines in total.

The first line contains an integer NN (1N201\le N\le 20), meaning there are NN switches. From line 22 onward, line ii describes switch ii.

In the next NN lines, the first number in each line is MM (0MN10\le M\le N-1), meaning the number of switches directly associated with switch ii. (The switches directly associated with those directly associated switches are naturally the switches indirectly associated with switch ii. When switch ii is pressed, only switch ii, its directly associated switches, and its indirectly associated switches will take effect.) Then follow MM integers, which are the indices of the switches directly associated with switch ii (if M=0M=0, it means there is no association).

Output Format

Output an integer ans\text{ans}, the minimum number of switch presses. If it is impossible to turn it off, output Change an alarm clock,please!.

5
4 2 3 4 5
2 1 3
2 1 4
2 1 5
1 1
2

Hint

Explanation of Sample 11:

First press 55. Its directly associated switch 11 will be turned off. Switch 11 indirectly turns off 22, 33, and 44, but turns 55 back on.

At this time, there has been 11 press in total, and switches 11, 22, 33, 44 are off.

Then press 22. Its directly associated switches 11 and 33 will be turned on. Switch 11 indirectly turns off 22, 33, and 55, and turns 44 back on. Switch 33 indirectly turns off 11 and 44.

At this time, there have been 22 presses in total, and switches 11, 22, 33, 44, 55 are all off, so the alarm is completely turned off.

Translated by ChatGPT 5