当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6386:Age of Moyu

题目描述
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)
输入解释
There might be multiple test cases, no more than $20$. You need to read till the end of input.

For each test case,In the first line, two integers $N$ $(2 \le N \le 100000)$ and $M$ $(0 \le M \le 200000)$, representing the number of ports and shipping lines in the city.

In the following m lines, each contain three integers, the first and second representing two ends $A_i$ and $B_i$ of a shipping line $(1 \le A_i, B_i \le N)$ and the third representing the identification number $C_i$ $(1 \le C_i \le 1000000)$ of Weitian who occupies this shipping line.
输出解释
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
输出样例
1
-1
2
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6386

最后修改于 2020-10-25T23:30:53+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000/2500MS(Java/Others) 262144/262144K(Java/Others)