結果

問題 No.17 2つの地点に泊まりたい
コンテスト
ユーザー tak
提出日時 2018-04-10 00:59:10
言語 F#
(F# 10.0)
コンパイル:
fsharp_c _filename_
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 214 ms / 5,000 ms
+ 260µs
コード長 1,326 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,065 ms
コンパイル使用メモリ 216,744 KB
実行使用メモリ 38,364 KB
最終ジャッジ日時 2026-07-17 04:24:22
合計ジャッジ時間 15,263 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (606 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

open System
open System.Collections.Generic

type WarshallFloyd(n,?isNonDir0:bool)=
    let isNonDir  = defaultArg isNonDir0 true
    let inf       = 1e16|>int64
    let vertexNum = n
    let edgeNum   = ref 0
    let costs     = Array2D.init<int64> (n+1) (n+1) 
                        (fun i j-> if i <> j then inf else 0L)
    member this.Inf = inf
    member this.AddPath f t c =
        incr edgeNum
        costs.[f,t]<-min costs.[f,t] c
        if isNonDir then 
            costs.[t,f]<-min costs.[t,f] c
    member this.Run() =
        for i in 0..vertexNum do
        for j in 0..vertexNum do
        for k in 0..vertexNum do
            costs.[j,k]<-min costs.[j,k] (costs.[j,i]+costs.[i,k])   
    member this.PathExist f t = costs.[f,t] <> inf
    member this.MinCosts()    = costs
    member this.MinCost f t   = costs.[f,t]

let read() = Console.ReadLine()

let N = read() |> int
let ws = WarshallFloyd(N)
let S = Array.init N (fun _ -> read() |> int64)
let M = read() |> int
for i in 0..M-1 do 
    let t = read().Split()
    ws.AddPath (t.[0] |> int) (t.[1] |> int) (t.[2] |> int64)

ws.Run()

[for i in [1..N-2] do for j in [1..N-2] do if i <> j then yield (i,j)]
|> List.map (fun (a,b) -> 
    (ws.MinCost 0 a) 
    + S.[a] + (ws.MinCost a b) + S.[b] 
    + (ws.MinCost b (N-1)))
|> List.min
|> printfn "%i"
0