Logo
(追記) (追記ここまで)

29998번 - Maximizing Flight Efficiency 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.5 초 (추가 시간 없음) 1024 MB58353170.455%

문제

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 considered coherent if no multi-stop route is cheaper than a direct flight.

Once the coherence of the table has been verified, the king would like to decrease the number of direct flights, without increasing the costs of the trips.

Your problem is to verify the coherence of the table and, if it is coherent, inform the king how many direct flights can be eliminated without increasing the cost of any trip.

입력

The first line of input contains an integer N (1 ≤ N ≤ 100), the number of cities in Quadradonia served by flights. Following there are N more lines, L1, L2, . . . , LN. Line Li contains N integers, Ci1, Ci2, . . . , CiN, where Cij is the cost of the direct flight between cities i and j.

The cost for an outbound and a return flight between two cities is always the same, meaning Cij = Cji for all pairs i, j where 1 ≤ i ≤ N and 1 ≤ j ≤ N. When i = j, Cij = 0. When i ≠ j, 1 ≤ Cij ≤ 103.

출력

Print a single line containing an integer. If the table is incoherent, the integer should be -1. If the table is coherent, the integer should be equal to the maximum number of direct flights that can be removed without increasing the costs of the trips for the passengers.

제한

예제 입력 1

3
0 1 2
1 0 1
2 1 0

예제 출력 1

1

예제 입력 2

3
0 2 2
2 0 2
2 2 0

예제 출력 2

0

예제 입력 3

3
0 2 9
2 0 2
9 2 0

예제 출력 3

-1

힌트

출처

ICPC > Regionals > Latin America > Sub-Regional Brasil do ACM ICPC > Maratona de Programação da SBC 2023 M번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /