結果

問題 No.1 道のショートカット
ユーザー YamaG NakaYamaG Naka
提出日時 2022-04-20 15:09:37
言語 Swift
(5.10.0)
結果
WA  
実行時間 -
コード長 1,619 bytes
コンパイル時間 9,820 ms
コンパイル使用メモリ 136,372 KB
実行使用メモリ 8,712 KB
最終ジャッジ日時 2023-09-02 09:19:21
合計ジャッジ時間 12,570 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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..<n {
    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>)>()
    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