結果
| 問題 |
No.2805 Go to School
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 22:39:37 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,766 bytes |
| コンパイル時間 | 417 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 77,952 KB |
| 最終ジャッジ日時 | 2024-07-12 22:40:06 |
| 合計ジャッジ時間 | 6,318 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 WA * 7 TLE * 2 -- * 12 |
コンパイルメッセージ
Main.rb:46: warning: assigned but unused variable - l Syntax OK
ソースコード
class BinaryHeap
def initialize
@data = Array.new
end
def size
@data.size
end
def empty?
@data.size == 0
end
def insert(x)
idx = @data.size
@data << x
while idx > 0 && priority(@data[idx], @data[(idx - 1) >> 1]) do
@data[(idx - 1) >> 1], @data[idx] = @data[idx], @data[(idx - 1) >> 1]
idx = (idx - 1) >> 1
end
end
alias << insert
def pop
return nil if @data.size == 0
return @data.pop if @data.size == 1
r = @data[0].dup
@data[0] = @data.pop
idx = 0
while (n_idx = 2 * idx + 1) < @data.size do
n_idx += 1 if n_idx + 1 < @data.size && priority(@data[n_idx + 1], @data[n_idx])
break if priority(@data[idx], @data[n_idx])
@data[idx], @data[n_idx] = @data[n_idx], @data[idx]
idx = n_idx
end
r
end
def top
self.empty? ? nil : @data[0]
end
private
def priority(a, b) # return true iff a has higher priority than b
(a >> 30) < (b >> 30)
end
end
INF = 1 << 30
Mask = (1 << 30) - 1
n, m, l, s, e = gets.split.map &:to_i
g = Array.new(n << 1) {[]}
m.times do
a, b, t = gets.split.map &:to_i
a -= 1
b -= 1
2.times do
g[a] << [b, t]
g[b] << [a, t]
a += n
b += n
end
end
t = Array.new(n, false)
gets.split.map(&:to_i).each do |i|
t[i - 1] = true
end
q = BinaryHeap.new
q << 0
dist = Array.new(n << 1, INF)
dist[0] = 0
while (ud = q.pop) do
u, d = ud & Mask, ud >> 30
next if dist[u] < d
g[u].each do |v, c|
next if dist[v] <= dist[u] + c
dist[v] = dist[u] + c
q << (dist[v] << 30 | v)
end
if t[u] && dist[u] < s + e && dist[u + n] > [dist[u] + 1, s + 1].max then
dist[u + n] = [dist[u] + 1, s + 1].max
q << (dist[u + n] << 30 | (u + n))
end
end
puts dist[-1] == INF ? -1 : dist[-1]