結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | yuruhiya |
提出日時 | 2021-04-11 18:45:51 |
言語 | Crystal (1.11.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,457 bytes |
コンパイル時間 | 13,335 ms |
コンパイル使用メモリ | 294,920 KB |
実行使用メモリ | 31,280 KB |
最終ジャッジ日時 | 2024-06-27 13:21:15 |
合計ジャッジ時間 | 25,092 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 553 ms
31,156 KB |
testcase_08 | AC | 670 ms
31,280 KB |
testcase_09 | AC | 525 ms
24,544 KB |
testcase_10 | AC | 48 ms
7,936 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 30 ms
6,940 KB |
testcase_14 | AC | 23 ms
6,944 KB |
testcase_15 | AC | 43 ms
6,944 KB |
testcase_16 | AC | 47 ms
8,320 KB |
testcase_17 | AC | 6 ms
6,940 KB |
testcase_18 | AC | 8 ms
6,940 KB |
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 | 40 ms
6,944 KB |
testcase_42 | AC | 41 ms
6,944 KB |
testcase_43 | AC | 173 ms
16,204 KB |
testcase_44 | AC | 178 ms
15,816 KB |
testcase_45 | AC | 176 ms
16,216 KB |
testcase_46 | AC | 292 ms
19,668 KB |
testcase_47 | AC | 375 ms
23,312 KB |
testcase_48 | AC | 362 ms
19,904 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) if 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(' ')