結果

問題 No.1607 Kth Maximum Card
ユーザー yuruhiyayuruhiya
提出日時 2021-07-17 14:40:47
言語 Crystal
(1.11.2)
結果
AC  
実行時間 1,374 ms / 3,500 ms
コード長 602 bytes
コンパイル時間 22,165 ms
コンパイル使用メモリ 253,616 KB
実行使用メモリ 41,496 KB
最終ジャッジ日時 2023-09-21 08:03:00
合計ジャッジ時間 37,980 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,332 KB
testcase_01 AC 3 ms
4,388 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,428 KB
testcase_04 AC 3 ms
4,416 KB
testcase_05 AC 2 ms
4,404 KB
testcase_06 AC 3 ms
4,332 KB
testcase_07 AC 3 ms
4,328 KB
testcase_08 AC 1,064 ms
41,496 KB
testcase_09 AC 779 ms
34,512 KB
testcase_10 AC 1,072 ms
40,804 KB
testcase_11 AC 111 ms
12,464 KB
testcase_12 AC 750 ms
33,616 KB
testcase_13 AC 83 ms
9,244 KB
testcase_14 AC 99 ms
11,732 KB
testcase_15 AC 775 ms
25,716 KB
testcase_16 AC 82 ms
10,544 KB
testcase_17 AC 21 ms
6,976 KB
testcase_18 AC 410 ms
22,812 KB
testcase_19 AC 229 ms
15,500 KB
testcase_20 AC 339 ms
16,116 KB
testcase_21 AC 375 ms
17,140 KB
testcase_22 AC 1,357 ms
39,784 KB
testcase_23 AC 1,374 ms
40,360 KB
testcase_24 AC 260 ms
21,416 KB
testcase_25 AC 117 ms
11,772 KB
testcase_26 AC 210 ms
12,404 KB
testcase_27 AC 321 ms
17,028 KB
testcase_28 AC 235 ms
15,168 KB
testcase_29 AC 588 ms
23,112 KB
testcase_30 AC 1,354 ms
40,508 KB
testcase_31 AC 561 ms
21,668 KB
testcase_32 AC 113 ms
12,492 KB
testcase_33 AC 114 ms
12,444 KB
testcase_34 AC 106 ms
12,564 KB
testcase_35 AC 107 ms
12,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, k = read_line.split.map(&.to_i)
g = Array.new(n) { [] of {Int32, Int32} }
m.times do
  u, v, c = read_line.split.map(&.to_i.pred)
  g[u] << {v, c + 1}
  g[v] << {u, c + 1}
end
puts (0..2*10**5).bsearch { |x|
  que = Deque{0}
  dist = Array(Int32?).new(n, nil)
  dist[0] = 0
  while v = que.shift?
    d = dist[v].not_nil!
    g[v].each do |u, c|
      cost = c > x ? 1 : 0
      d2 = d + cost
      if (d3 = dist[u]).nil? || d2 < d3
        dist[u] = d2
        if cost == 0
          que.unshift u
        else
          que.push u
        end
      end
    end
  end
  dist.last.not_nil! < k
}
0