6755.Flight Discount

Time Limit: 1s Memory Limit: 512MB

Your task is to find a minimum-price flight route from Syrjälä to Metsälä. You have one discount coupon, using which you can halve the price of any single flight during the route. However, you can only use the coupon once.

When you use the discount coupon for a flight whose price is $x$ , its price becomes $\lfloor x/2 \rfloor$ (it is rounded down to an integer).

Input Format(From the terminal/stdin)

The first input line has two integers $n$ and $m$ : the number of cities and flight connections. The cities are numbered $1,2,\ldots,n$ . City 1 is Syrjälä, and city $n$ is Metsälä.

After this there are $m$ lines describing the flights. Each line has three integers $a$ , $b$ , and $c$ : a flight begins at city $a$ , ends at city $b$ , and its price is $c$ . Each flight is unidirectional.

You can assume that it is always possible to get from Syrjälä to Metsälä.

  • $2 \le n \le 10^5$
  • $1 \le m \le 2 \cdot 10^5$
  • $1 \le a,b \le n$
  • $1 \le c \le 10^9$

Output Format(To the terminal/stdout)

Print one integer: the price of the cheapest route from Syrjälä to Metsälä.

Sample Input

Copy
3 4
1 2 3
2 3 1
1 3 7
2 1 5
 · \n
 · · \n
 · · \n
 · · \n
 · · \n

Sample Output

Copy
2
 \n
Source: CSES, Graph Algorithms, 1195

Submit

请先 登录

© 2025 FAQs