P4906 Turn Off the Alarm Clock

Background

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

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+1$ lines in total. The first line contains an integer $N$ ($1\le N\le 20$), meaning there are $N$ switches. From line $2$ onward, line $i$ describes switch $i$. In the next $N$ lines, the first number in each line is $M$ ($0\le M\le N-1$), meaning the number of switches directly associated with switch $i$. (The switches directly associated with those directly associated switches are naturally the switches indirectly associated with switch $i$. When switch $i$ is pressed, only switch $i$, its directly associated switches, and its indirectly associated switches will take effect.) Then follow $M$ integers, which are the indices of the switches directly associated with switch $i$ (if $M=0$, it means there is no association).

Output Format

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

Explanation/Hint

Explanation of Sample $1$: First press $5$. Its directly associated switch $1$ will be turned off. Switch $1$ indirectly turns off $2$, $3$, and $4$, but turns $5$ back on. At this time, there has been $1$ press in total, and switches $1$, $2$, $3$, $4$ are off. Then press $2$. Its directly associated switches $1$ and $3$ will be turned on. Switch $1$ indirectly turns off $2$, $3$, and $5$, and turns $4$ back on. Switch $3$ indirectly turns off $1$ and $4$. At this time, there have been $2$ presses in total, and switches $1$, $2$, $3$, $4$, $5$ are all off, so the alarm is completely turned off. Translated by ChatGPT 5