#P4400. [JSOI2008] Blue Mary的旅行
[JSOI2008] Blue Mary的旅行
Description
After some time, the network company finally gained some recognition and started receiving orders, the biggest of which came from city B.
Blue Mary decided to personally go and sign this order. To save travel expenses, one of his financial advisors suggested buying tickets only from U Airlines. All flights of U Airlines operate once per day, departing in the morning and arriving in the afternoon of the same day, so each person can take at most one flight per day.
After investigation, they obtained detailed information on all flights operated by U Airlines, including each flight’s origin, destination, and the maximum number of tickets that can be bought for departures on any single day. (Note: For a given flight, the maximum number of tickets they can buy for departures on any day is the same across all days.)
Blue Mary noticed that they can indeed travel from city A to city B using only U Airlines’ flights. However, due to the ticket limits on each flight, it may be impossible for all of them to arrive in city B on the same day.
Therefore, Blue Mary needs your help to design a travel plan that makes the arrival day of the last person to reach city B as early as possible.
Input Format
The first line contains positive integers , and .
All cities that appear in the problem are numbered , where city A is numbered , and city B is numbered .
U Airlines has directed flights in total. Including Blue Mary, the company has people who need to travel from city A to city B.
The following lines each contain positive integers , indicating the origin, destination, and the maximum number of tickets that Blue Mary can buy for that flight on any given day. (That is, regardless of the day, Blue Mary can buy at most tickets for the U Airlines flight from city to city .)
It is guaranteed that between any ordered pair of cities, there is at most one directed flight.
Output Format
Output a single line with one positive integer, the earliest possible day on which the last person arrives in city B. Assume the first day they take a flight is day .
3 3 5
1 2 1
2 3 5
3 1 4
6
Hint
For of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号