Problem A. Age of Moyu
时间限制 2500 ms
内存限制 256 MB
Mr.Quin love fishes so much and Mr.Quin’s city has a nautical system,consisiting of $N$ ports and $M$ shipping lines. The ports are numbered $1$ to $N$. Each line is occupied by a Weitian. Each Weitian has an identification number.
The $i$-th $(1 \leq i \le M)$ line connects port $A_i$ and $B_i$ $(A_i \ne B_i )$ bidirectionally, and occupied by $C_i$ Weitian (At most one line between two ports).
When Mr.Quin only uses lines that are occupied by the same Weitian, the cost is $1$ XiangXiangJi. Whenever Mr.Quin changes to a line that is occupied by a different Weitian from the current line, Mr.Quin is charged an additional cost of $1$ XiangXiangJi. In a case where Mr.Quin changed from some Weitian $A$'s line to another Weitian's line changes to Weitian $A$'s line again, the additional cost is incurred again.
Mr.Quin is now at port $1$ and wants to travel to port $N$ where live many fishes. Find the minimum required XiangXiangJi (If Mr.Quin can’t travel to port $N$, print $-1$ instead)
输入数据
输出数据
For each test case output the minimum required cost. If Mr.Quin can’t travel to port $N$, output $-1$ instead.
样例输入
复制
3 3
1 2 1
1 3 2
2 3 1
2 0
3 2
1 2 1
2 3 2
样例输出
$ Mathjax font initiator $