結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | yuruhiya |
提出日時 | 2021-04-11 18:44:48 |
言語 | Crystal (1.11.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,461 bytes |
コンパイル時間 | 13,206 ms |
コンパイル使用メモリ | 295,420 KB |
実行使用メモリ | 27,008 KB |
最終ジャッジ日時 | 2024-06-27 13:20:14 |
合計ジャッジ時間 | 22,974 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 29 ms
5,504 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
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 | WA | - |
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 | AC | 37 ms
6,528 KB |
testcase_42 | AC | 38 ms
6,656 KB |
testcase_43 | AC | 126 ms
12,160 KB |
testcase_44 | AC | 125 ms
12,160 KB |
testcase_45 | AC | 127 ms
12,044 KB |
testcase_46 | AC | 231 ms
14,972 KB |
testcase_47 | AC | 272 ms
17,492 KB |
testcase_48 | AC | 266 ms
16,348 KB |
ソースコード
# require "template" lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end # require "graph" struct Edge(T) property to : Int32 property cost : T def initialize(@to : Int32, @cost : T) end end struct Edge2(T) property from : Int32 property to : Int32 property cost : T def initialize(@from : Int32, @to : Int32, @cost : T) end end class Graph(T) getter size : Int32 getter graph : Array(Array(Edge(T))) def initialize(@size : Int32) @graph = Array.new(size) { Array(Edge(T)).new } end def initialize(@size, edges : Array(Edge2(T)), undirected : Bool) @graph = Array.new(size) { Array(Edge(T)).new } edges.each do |edge| @graph[edge.from] << Edge.new(edge.to, edge.cost) @graph[edge.to] << Edge.new(edge.from, edge.cost) unless undirected end end def add_edge(i : Int32, j : Int32, cost : T) graph[i] << Edge(T).new(j, cost) graph[j] << Edge(T).new(i, cost) end end # require "graph/bfs" # require "./graph" class Graph(T) def bfs(start : Int32, unreachable : T = nil) forall T raise ArgumentError.new unless 0 <= start < size queue = Deque(Int32).new queue << start dist = Array(Int32?).new(size, nil) dist[start] = 0 while v = queue.pop? graph[v].each do |edge| if dist[edge.to].nil? dist[edge.to] = dist[v].not_nil! + 1 queue << edge.to end end end dist.map { |i| i ? i : unreachable } end def bfs_st(start : Int32, goal : Int32, unreachable : T = nil) forall T raise ArgumentError.new unless 0 <= start < size queue = Deque(Int32).new queue << start dist = Array(Int32?).new(size, nil) dist[start] = 0 while v = queue.pop? return dist[v].not_nil! if v == goal graph[v].each do |edge| if dist[edge.to].nil? dist[edge.to] = dist[v].not_nil! + 1 queue << edge.to end end end unreachable end end n, m = read_line.split.map(&.to_i) edges = (0...m).map { s, t, d = read_line.split.map(&.to_i) Edge2(Int32).new(s - 1, t - 1, d) } ans = (1..10**9 + 1).bsearch { |weight| graph = Graph.new(n, edges.select { |edge| edge.cost >= weight }, undirected: true) graph.bfs(0).last.nil? }.not_nil! - 1 graph = Graph.new(n, edges.select { |edge| edge.cost >= ans }, undirected: true) puts [ans, graph.bfs_st(0, n - 1)].join(' ')