1859: Pesky Heroes

[提交][状态][讨论版][命题人:]

输入

The input will consist of several data sets. Each set will start with a line consisting of two numbers, n, m where 2 ≤ n ≤ 50000 is the number of key points on the map and 0 ≤ m ≤ 500 is the number of traps. The next n lines will consist of 2 to 4 space-separated integers. Line i contains an integer ni, 1 ≤ ni ≤ 3, the number of passages connecting to key point i, followed by a list of the ni key points that the passages lead to, in clockwise order. The next m lines consist of single integers, the key points at which there are traps. Key points are labelled 1, ..., n and key point 1 is the (implicit) entrance to the outside world. Key point 1 is guaranteed to always have exactly one passage. The last case will be followed by a line with m = n = 0, which should not be processed.

输出

For each case, output the minimum number of gateways required, on a line by itself.

样例输入

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

样例输出

1
0

[提交][状态]