#FW0000112. Nhu cầu của Chokudai (Chokudai's Demand)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nhu cầu của Chokudai (Chokudai's Demand)
Chokudai's Demand
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are cities and an undirected direct road between every pair. The road cost is fixed when not equal to ; otherwise its cost is a common unknown positive integer . For each , count unordered pairs whose shortest-path distance does not exceed . Determine how many positive integers make this count exactly . Print Infinity if there are infinitely many valid values. Travel through intermediate cities is allowed.
Input
First line: . Next lines: the symmetric matrix with and off-diagonal entries equal to or positive integers.
Output
Print the number of valid values of , or Infinity.
Subtasks
-
Subtask 1 (40 points): , , , . All input conditions remain in force.
-
Subtask 2 (60 points): , , , . All input conditions remain in force.
Examples
Input
3 4 2
0 3 -1
3 0 5
-1 5 0
Output
3
Explanation
Exactly X=2,3,4 produce two city pairs at distance at most 4; therefore the answer is 3.