fork download
  1. type InfiniteInt =
  2. | Real of int
  3. | Infinity
  4. with
  5. member this.toString =
  6. match this with
  7. | Real(n) -> n.ToString()
  8. | Infinity -> "Infinity"
  9.  
  10. let inline (+) (x : InfiniteInt) (y : InfiniteInt) =
  11. match (x, y) with
  12. | (Infinity, _) -> Infinity
  13. | (_, Infinity) -> Infinity
  14. | (Real(n), Real(m)) -> Real(n + m)
  15.  
  16. let inline (>) (x : InfiniteInt) (y : InfiniteInt) =
  17. match (x, y) with
  18. | (Infinity, Real(_)) -> true
  19. | (Infinity, Infinity) -> false
  20. | (Real(_), Infinity) -> false
  21. | (Real(n), Real(m)) -> n > m
  22.  
  23. let split (c : char) (n : System.String) = n.Split(c)
  24.  
  25. [<EntryPoint>]
  26. let main argv =
  27. let vertexes = int (System.Console.ReadLine())
  28. let adjMatrix = Array2D.init<InfiniteInt> vertexes vertexes (fun _ __ -> Infinity)
  29. for x in [0..(vertexes - 1)] do
  30. adjMatrix.[x, x] <- Real(0)
  31. let line = System.Console.ReadLine() |> split ' '
  32. for y in [0 .. (Array.length line) - 1] do if line.[y] = "1" then adjMatrix.[x,y] <- Real(1)
  33. for x in [0..(vertexes - 1)] do
  34. for y in [0..(vertexes - 1)] do
  35. for z in [0..(vertexes - 1)] do
  36. let sum = adjMatrix.[y,x] + adjMatrix.[x, z]
  37. if adjMatrix.[y, z] > sum then adjMatrix.[y, z] <- sum
  38. let radius =
  39. let maxRadiuses =
  40. [for x in [0..(vertexes - 1)]
  41. ->
  42. [for y in [0..(vertexes - 1)] -> adjMatrix.[x, y]] |> List.max
  43. ]
  44. maxRadiuses |> List.min
  45. printfn "%s" radius.toString
  46. 0
Success #stdin #stdout 0.15s 12160KB
stdin
10
0 1 0 0 1 1 0 0 0 0
1 0 1 0 0 0 1 0 0 0
0 1 0 1 0 0 0 1 0 0
0 0 1 0 1 0 0 0 1 0
1 0 0 1 0 0 0 0 0 1
1 0 0 0 0 0 0 1 1 0
0 1 0 0 0 0 0 0 1 1
0 0 1 0 0 1 0 0 0 1
0 0 0 1 0 1 1 0 0 0
0 0 0 0 1 0 1 1 0 0
stdout
2