Meeting

Time Limit: 12000/6000 MS (Java/Others)

Memory Limit: 262144/262144 K (Java/Others)

Description

Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated his
fences they were separated into different blocks. John's farm are divided into $n$ blocks labelled from $1$ to $n$.
Bessie lives in the first block while Elsie lives in the $n$-th one. They have a map of the farm
which shows that it takes they $t_i$ minutes to travel from a block in $E_i$ to another block
in $E_i$ where $E_i~(1\le i\le m)$ is a set of blocks. They want to know how soon they can meet each other
and which block should be chosen to have the meeting.

Input

The first line contains an integer $T~(1\le T\le 6)$, the number of test cases. Then $T$ test cases
follow.

The first line of input contains $n$ and $m$. $2 \leq n \leq 10^5$. The following $m$ lines describe the sets $E_i~(1\le i\le m)$. Each line will contain two integers $t_i(1 \leq t_i \leq 10^9)$ and $S_i~(S_i>0)$ firstly. Then $S_i$ integer follows which are the labels of blocks in $E_i$. It is guaranteed that $\sum_{i=1}^m{S_i} \leq 10^6$.

Output

For each test case, if they cannot have the meeting, then output "Evil John" (without quotes) in one line.

Otherwise, output two lines. The first line contains an integer, the time it takes for they to meet.
The second line contains the numbers of blocks where they meet. If there are multiple
optional blocks, output all of them in ascending order.

Sample Input

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

Sample Output

Case #1: 3 3 4 Case #2: Evil John
Hint
In the first case, it will take Bessie 1 minute travelling to the 3rd block, and it will take Elsie 3 minutes travelling to the 3rd block. It will take Bessie 3 minutes travelling to the 4th block, and it will take Elsie 3 minutes travelling to the 4th block. In the second case, it is impossible for them to meet.

Hint

wange2014

Source

2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

提交代码