A1272 | [COCI-2012_2013-contest5]#2 HIPERCIJEVI
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
In a galaxy far, far away, the fastest method of transportation is using hypertubes. Each hypertube directly connects K stations with each other. What is the minimum number of stations that we need to pass through in order to get from station 1 to station N?
输入格式
The first line of input contains three positive integers: N (1 ≤ N ≤ 100 000), the number of stations, K (1 ≤ K ≤ 1 000), the number of stations that any single hypertube directly interconnects, and M (1 ≤ M ≤ 1 000), the number of hypertubes.
Each of the following M lines contains the description of a single hypertube: K positive integers, the labels of stations connected to that hypertube.
Each of the following M lines contains the description of a single hypertube: K positive integers, the labels of stations connected to that hypertube.
输出格式
The first and only line of output must contain the required minimum number of stations. If it isn't possible to travel from station 1 to station N, output -
1.
1.
输入输出样例
输入 #1
9 3 5 1 2 3 1 4 5 3 6 7 5 6 7 6 8 9
输出 #1
4
输入 #2
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
输出 #2
3
Clarification of the first example: It is possible to travel from station 1 to station 9 using only four
stations in the following ways: 1-3-6-9, or 1-5-6-9.
stations in the following ways: 1-3-6-9, or 1-5-6-9.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted