Maximizing Flight Efficiency
InterviewTime limit0.5sMemory limit1024 MB
Check whether any direct flight is more expensive than a multi-stop route, and if not, count the direct flights that can be removed without changing any trip cost.
- Level
Medium5 of 10
- Topics
- Shortest path, Matrix, Graph
- Solved
- No attempts yet
Problem
In the kingdom of Quadradonia, the king wants to review the prices of flights. For this purpose, he asked his accountant for a table with proposals for new prices.
However, the king studied at the Institute of Computing and Programming of Chapec´o (ICPC) and has sufficient knowledge to demand coherence in the table. The table is coherent if no multi-stop route is cheaper than a direct flight.
Once the table has been verified as coherent, the king wants to reduce the number of direct flights without increasing the cost of any trip.
Your task is to verify whether the table is coherent. If it is, find the maximum number of direct flights that can be removed without increasing the cost of any trip.
Input
The first line contains an integer (), the number of cities served by flights. The next lines are . Line contains integers , where is the cost of the direct flight between cities and .
The cost of a flight is the same in both directions, so for all . When , . When , .
Output
If the table is not coherent, print . If it is coherent, print one integer on a single line: the maximum number of direct flights that can be removed without increasing the cost of any trip for passengers.