#P7646. [COCI 2012/2013 #5] HIPERCIJEVI

    ID: 8489 远端评测题 1000ms 32MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2012COCI(克罗地亚)

[COCI 2012/2013 #5] HIPERCIJEVI

Problem Description

In a galaxy far, far away, the fastest method of transportation is using hypertubes. Each hypertube directly connects KK stations with each other. What is the minimum number of stations that we need to pass through in order to get from station 11 to station NN?

Input Format

The first line of input contains three positive integers: NN ( 1N1000001 \le N \le 100000 ), the number of stations, KK ( 1K10001 \le K \le 1000 ), the number of stations that any single hypertube directly interconnects, and MM ( 1M10001 \le M \le 1000 ), the number of hypertubes.

Each of the following MM lines contains the description of a single hypertube: KK positive integers, the labels of stations connected to that hypertube.

Output Format

The first and only line of output must contain the required minimum number of stations. If it isn't possible to travel from station 11 to station NN, output 1-1.

9 3 5
1 2 3
1 4 5
3 6 7
5 6 7
6 8 9
4
15 8 4
11 12 8 14 13 6 10 7
1 5 8 12 13 6 2 4
10 15 4 5 9 8 14 12
11 12 14 3 5 6 1 13
3

Hint

Clarification of the first example: It is possible to travel from station 11 to station 99 using only four stations in the following ways: 11-33-66-99, or 11-55-66-99.

Source:COCI2012~2013 CONTEST#5 T4 HIPERCIJEVI