CF576D.Flights for Regular Customers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In the country there are exactly nn cities numbered with positive integers from 11 to nn . In each city there is an airport is located.

Also, there is the only one airline, which makes mm flights. Unfortunately, to use them, you need to be a regular customer of this company, namely, you have the opportunity to enjoy flight ii from city aia_{i} to city bib_{i} only if you have already made at least did_{i} flights before that.

Please note that flight ii flies exactly from city aia_{i} to city bib_{i} . It can not be used to fly from city bib_{i} to city aia_{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 11 to city nn . Unfortunately, you've never traveled by plane before. What minimum number of flights you have to perform in order to get to city nn ?

Note that the same flight can be used multiple times.

输入格式

The first line contains two integers, nn and mm ( 2<=n<=1502<=n<=150 , 1<=m<=1501<=m<=150 ) — the number of cities in the country and the number of flights the company provides.

Next mm lines contain numbers aia_{i} , bib_{i} , did_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n , 0<=di<=1090<=d_{i}<=10^{9} ), representing flight number ii from city aia_{i} to city bib_{i} , accessible to only the clients who have made at least did_{i} flights.

输出格式

Print "Impossible" (without the quotes), if it is impossible to get from city 11 to city nn 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.

输入输出样例

  • 输入#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
    
首页