結果

問題 No.1 道のショートカット
ユーザー YamaG NakaYamaG Naka
提出日時 2022-04-20 15:58:52
言語 Swift
(5.10.0)
結果
MLE  
実行時間 -
コード長 1,672 bytes
コンパイル時間 13,112 ms
コンパイル使用メモリ 138,428 KB
実行使用メモリ 817,708 KB
最終ジャッジ日時 2023-09-02 10:15:30
合計ジャッジ時間 12,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,460 KB
testcase_01 AC 3 ms
8,384 KB
testcase_02 AC 3 ms
8,328 KB
testcase_03 AC 3 ms
8,408 KB
testcase_04 AC 4 ms
8,460 KB
testcase_05 AC 3 ms
8,356 KB
testcase_06 AC 3 ms
8,400 KB
testcase_07 AC 3 ms
8,372 KB
testcase_08 AC 12 ms
8,992 KB
testcase_09 AC 7 ms
8,496 KB
testcase_10 AC 21 ms
9,956 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

let n = Int(readLine()!)!
let c = Int(readLine()!)!
let v = Int(readLine()!)!
let s=readLine()!.split(separator:" ").map({Int($0)!})
let t=readLine()!.split(separator:" ").map({Int($0)!})
let y=readLine()!.split(separator:" ").map({Int($0)!})
let m=readLine()!.split(separator:" ").map({Int($0)!})
var br=[Int:[(Int,Int,Int)]]()
for i in 0..<v {
    let s=s[i]-1,g=t[i]-1,time=m[i],cost=y[i]
    br[s,default:[(Int,Int,Int)]()]+=[(g,time,cost)]
    //有向グラフ
}

func bfs() -> Int {
    let start=0
    var queue = ArraySlice<(Int,Int,Int,Set<Int>)>()
    //node,time,cost,explored
    queue.append((start, 0,0,Set<Int>()))
    var mintime = -1
    while let (curnode, time, cost,explored) = queue.popFirst() {
        if let branches=br[curnode] {
            for (nextnode,timeplus,costplus) in branches {
                if !explored.contains(nextnode) {
                    let newcost=cost+costplus
                    if newcost <= c {
                        let newtime=time+timeplus
                        if nextnode==n-1 {
                            //print("first goal!!")
                            //return newtime
                            if mintime == -1 {
                                mintime=newtime
                            } else {
                                mintime = min(mintime,newtime)
                            }
                        }
                        var newexplored=explored
                        newexplored.insert(nextnode)
                        queue.append((nextnode,newtime,newcost,newexplored))
                    }
                }
            }
        }
    }
    return mintime
}
print(bfs())
0