結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | yuruhiya |
提出日時 | 2021-04-11 18:52:37 |
言語 | Crystal (1.11.2) |
結果 |
AC
|
実行時間 | 711 ms / 2,000 ms |
コード長 | 2,615 bytes |
コンパイル時間 | 11,251 ms |
コンパイル使用メモリ | 294,812 KB |
実行使用メモリ | 30,976 KB |
最終ジャッジ日時 | 2024-06-27 13:33:14 |
合計ジャッジ時間 | 23,857 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 575 ms
23,168 KB |
testcase_03 | AC | 332 ms
15,616 KB |
testcase_04 | AC | 299 ms
11,520 KB |
testcase_05 | AC | 91 ms
7,552 KB |
testcase_06 | AC | 419 ms
17,792 KB |
testcase_07 | AC | 588 ms
30,976 KB |
testcase_08 | AC | 711 ms
23,040 KB |
testcase_09 | AC | 555 ms
24,704 KB |
testcase_10 | AC | 50 ms
10,240 KB |
testcase_11 | AC | 47 ms
8,064 KB |
testcase_12 | AC | 51 ms
8,064 KB |
testcase_13 | AC | 30 ms
5,504 KB |
testcase_14 | AC | 24 ms
5,376 KB |
testcase_15 | AC | 42 ms
6,528 KB |
testcase_16 | AC | 48 ms
8,320 KB |
testcase_17 | AC | 6 ms
5,376 KB |
testcase_18 | AC | 8 ms
5,376 KB |
testcase_19 | AC | 68 ms
6,528 KB |
testcase_20 | AC | 218 ms
13,312 KB |
testcase_21 | AC | 145 ms
9,600 KB |
testcase_22 | AC | 139 ms
18,176 KB |
testcase_23 | AC | 117 ms
16,768 KB |
testcase_24 | AC | 108 ms
15,744 KB |
testcase_25 | AC | 605 ms
24,576 KB |
testcase_26 | AC | 576 ms
18,304 KB |
testcase_27 | AC | 158 ms
8,704 KB |
testcase_28 | AC | 492 ms
21,120 KB |
testcase_29 | AC | 220 ms
18,048 KB |
testcase_30 | AC | 350 ms
27,648 KB |
testcase_31 | AC | 400 ms
22,784 KB |
testcase_32 | AC | 234 ms
15,360 KB |
testcase_33 | AC | 214 ms
13,056 KB |
testcase_34 | AC | 116 ms
12,032 KB |
testcase_35 | AC | 82 ms
6,912 KB |
testcase_36 | AC | 204 ms
10,300 KB |
testcase_37 | AC | 343 ms
15,872 KB |
testcase_38 | AC | 50 ms
5,888 KB |
testcase_39 | AC | 46 ms
8,064 KB |
testcase_40 | AC | 46 ms
7,936 KB |
testcase_41 | AC | 39 ms
6,656 KB |
testcase_42 | AC | 39 ms
6,912 KB |
testcase_43 | AC | 177 ms
16,000 KB |
testcase_44 | AC | 177 ms
15,872 KB |
testcase_45 | AC | 178 ms
16,256 KB |
testcase_46 | AC | 305 ms
19,712 KB |
testcase_47 | AC | 412 ms
23,296 KB |
testcase_48 | AC | 382 ms
19,328 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) raise ArgumentError.new("Negative graph size: #{size}") if size < 0 @graph = Array.new(size) { Array(Edge(T)).new } end def initialize(@size, edges : Array(Edge2(T)), undirected : Bool) raise ArgumentError.new("Negative graph size: #{size}") if size < 0 @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.unshift 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.unshift 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.unshift start dist = Array(Int32?).new(size, nil) dist[start] = 0 while v = queue.pop? d = dist[v].not_nil! return d if v == goal graph[v].each do |edge| if dist[edge.to].nil? dist[edge.to] = d + 1 queue.unshift 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(' ')