A7997 | Shortest Path
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In Ancient Berland there were $n$ cities and $m$ two-way roads of equal length. The cities are numbered with integers from $1$ to $n$ inclusively. According to an ancient superstition, if a traveller visits three cities $a_{i}$ , $b_{i}$ , $c_{i}$ in row, without visiting other cities between them, a great disaster awaits him. Overall there are $k$ such city triplets. Each triplet is ordered, which means that, for example, you are allowed to visit the cities in the following order: $a_{i}$ , $c_{i}$ , $b_{i}$ . Vasya wants to get from the city $1$ to the city $n$ and not fulfil the superstition. Find out which minimal number of roads he should take. Also you are required to find one of his possible path routes.
输入格式
The first line contains three integers $n$ , $m$ , $k$ ( $2<=n<=3000,1<=m<=20000,0<=k<=10^{5}$ ) which are the number of cities, the number of roads and the number of the forbidden triplets correspondingly.
Then follow $m$ lines each containing two integers $x_{i}$ , $y_{i}$ ( $1<=x_{i},y_{i}<=n$ ) which are the road descriptions. The road is described by the numbers of the cities it joins. No road joins a city with itself, there cannot be more than one road between a pair of cities.
Then follow $k$ lines each containing three integers $a_{i}$ , $b_{i}$ , $c_{i}$ ( $1<=a_{i},b_{i},c_{i}<=n$ ) which are the forbidden triplets. Each ordered triplet is listed mo more than one time. All three cities in each triplet are distinct.
City $n$ can be unreachable from city $1$ by roads.
Then follow $m$ lines each containing two integers $x_{i}$ , $y_{i}$ ( $1<=x_{i},y_{i}<=n$ ) which are the road descriptions. The road is described by the numbers of the cities it joins. No road joins a city with itself, there cannot be more than one road between a pair of cities.
Then follow $k$ lines each containing three integers $a_{i}$ , $b_{i}$ , $c_{i}$ ( $1<=a_{i},b_{i},c_{i}<=n$ ) which are the forbidden triplets. Each ordered triplet is listed mo more than one time. All three cities in each triplet are distinct.
City $n$ can be unreachable from city $1$ by roads.
输出格式
If there are no path from $1$ to $n$ print -1. Otherwise on the first line print the number of roads $d$ along the shortest path from the city $1$ to the city $n$ . On the second line print $d+1$ numbers — any of the possible shortest paths for Vasya. The path should start in the city $1$ and end in the city $n$ .
输入输出样例
输入 #1
4 4 1 1 2 2 3 3 4 1 3 1 4 3
输出 #1
2 1 3 4
输入 #2
3 1 0 1 2
输出 #2
-1
输入 #3
4 4 2 1 2 2 3 3 4 1 3 1 2 3 1 3 4
输出 #3
4 1 3 2 3 4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted