A10022 | Flights for Regular Customers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In the country there are exactly $n$ cities numbered with positive integers from $1$ to $n$ . In each city there is an airport is located.
Also, there is the only one airline, which makes $m$ flights. Unfortunately, to use them, you need to be a regular customer of this company, namely, you have the opportunity to enjoy flight $i$ from city $a_{i}$ to city $b_{i}$ only if you have already made at least $d_{i}$ flights before that.
Please note that flight $i$ flies exactly from city $a_{i}$ to city $b_{i}$ . It can not be used to fly from city $b_{i}$ to city $a_{i}$ . An interesting fact is that there may possibly be recreational flights with a beautiful view of the sky, which begin and end in the same city.
You need to get from city $1$ to city $n$ . Unfortunately, you've never traveled by plane before. What minimum number of flights you have to perform in order to get to city $n$ ?
Note that the same flight can be used multiple times.
Also, there is the only one airline, which makes $m$ flights. Unfortunately, to use them, you need to be a regular customer of this company, namely, you have the opportunity to enjoy flight $i$ from city $a_{i}$ to city $b_{i}$ only if you have already made at least $d_{i}$ flights before that.
Please note that flight $i$ flies exactly from city $a_{i}$ to city $b_{i}$ . It can not be used to fly from city $b_{i}$ to city $a_{i}$ . An interesting fact is that there may possibly be recreational flights with a beautiful view of the sky, which begin and end in the same city.
You need to get from city $1$ to city $n$ . Unfortunately, you've never traveled by plane before. What minimum number of flights you have to perform in order to get to city $n$ ?
Note that the same flight can be used multiple times.
输入格式
The first line contains two integers, $n$ and $m$ ( $2<=n<=150$ , $1<=m<=150$ ) — the number of cities in the country and the number of flights the company provides.
Next $m$ lines contain numbers $a_{i}$ , $b_{i}$ , $d_{i}$ ( $1<=a_{i},b_{i}<=n$ , $0<=d_{i}<=10^{9}$ ), representing flight number $i$ from city $a_{i}$ to city $b_{i}$ , accessible to only the clients who have made at least $d_{i}$ flights.
Next $m$ lines contain numbers $a_{i}$ , $b_{i}$ , $d_{i}$ ( $1<=a_{i},b_{i}<=n$ , $0<=d_{i}<=10^{9}$ ), representing flight number $i$ from city $a_{i}$ to city $b_{i}$ , accessible to only the clients who have made at least $d_{i}$ flights.
输出格式
Print "Impossible" (without the quotes), if it is impossible to get from city $1$ to city $n$ using the airways.
But if there is at least one way, print a single integer — the minimum number of flights you need to make to get to the destination point.
But if there is at least one way, print a single integer — the minimum number of flights you need to make to get to the destination point.
输入输出样例
输入 #1
3 2 1 2 0 2 3 1
输出 #1
2
输入 #2
2 1 1 2 100500
输出 #2
Impossible
输入 #3
3 3 2 1 0 2 3 6 1 2 0
输出 #3
8
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted