結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2022-04-20 15:58:52 |
言語 | Swift (6.0.3) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,672 bytes |
コンパイル時間 | 9,888 ms |
コンパイル使用メモリ | 138,388 KB |
実行使用メモリ | 814,192 KB |
最終ジャッジ日時 | 2024-06-11 16:57:05 |
合計ジャッジ時間 | 14,323 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 MLE * 1 -- * 32 |
ソースコード
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())