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 lines in total.
The first line contains an integer (), meaning there are switches. From line onward, line describes switch .
In the next lines, the first number in each line is (), meaning the number of switches directly associated with switch . (The switches directly associated with those directly associated switches are naturally the switches indirectly associated with switch . When switch is pressed, only switch , its directly associated switches, and its indirectly associated switches will take effect.) Then follow integers, which are the indices of the switches directly associated with switch (if , it means there is no association).
Output Format
Output an integer , 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 :
First press . Its directly associated switch will be turned off. Switch indirectly turns off , , and , but turns back on.
At this time, there has been press in total, and switches , , , are off.
Then press . Its directly associated switches and will be turned on. Switch indirectly turns off , , and , and turns back on. Switch indirectly turns off and .
At this time, there have been presses in total, and switches , , , , are all off, so the alarm is completely turned off.
Translated by ChatGPT 5