Submission #51755608
Source Code Expand
class PQ
def initialize
@h = [] # min-heap
end
def head
@h[0]
end
def enq c,a
@h << [c,a]
up_heap
end
def deq
return unless @h[0]
@h[0],@h[-1] = @h[-1],@h[0]
c,a = @h.pop
dn_heap if @h[0]
return c,a
end
private
def up_heap
c, = up = @h[i=@h.size-1]
while 0<i
iP = (i-1)/2
break if @h[iP][0]<=c
@h[i],i = @h[iP],iP
end
@h[i] = up
end
def dn_heap
c, = dn = @h[i=0]
z = @h.size
until z <= iC = i+i+1
iC += 1 if iC+1<z && @h[iC+1][0]<@h[iC][0]
break if c<=@h[iC][0]
@h[i],i = @h[iC],iC
end
@h[i] = dn
end
end
N,M = gets.split.map(&:to_i)
E = Array.new(N+1){[]}
M.times{
a,b,c = gets.split.map(&:to_i)
E[a]<<[b,c]
E[b]<<[a,c]
}
U = 10**10
T = [U*N]*(N+1)
T[1] = 0
Q = PQ.new
Q.enq 0,1
while (t,a = Q.deq)
E[a].each{|b,c|
t1 = c<0 ? t+U+1 : t%U<c ? t-t%U+c+1 : t+1
T[b] = t1 and Q.enq t1,b if t1<T[b]
} if t==T[a]
end
p T[N]%U
Submission Info
| Submission Time | |
|---|---|
| Task | H - Winter Road |
| User | ds14050 |
| Language | Ruby (ruby 3.2.2) |
| Score | 400 |
| Code Size | 968 Byte |
| Status | AC |
| Exec Time | 704 ms |
| Memory | 62944 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | example0.txt, example1.txt, random0.txt, random1.txt, random10.txt, random11.txt, random12.txt, random13.txt, random14.txt, random15.txt, random16.txt, random17.txt, random18.txt, random19.txt, random2.txt, random20.txt, random21.txt, random22.txt, random23.txt, random24.txt, random25.txt, random26.txt, random27.txt, random28.txt, random29.txt, random3.txt, random30.txt, random31.txt, random32.txt, random33.txt, random34.txt, random35.txt, random36.txt, random37.txt, random38.txt, random39.txt, random4.txt, random5.txt, random6.txt, random7.txt, random8.txt, random9.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| example0.txt | AC | 117 ms | 17032 KiB |
| example1.txt | AC | 43 ms | 17000 KiB |
| random0.txt | AC | 446 ms | 47608 KiB |
| random1.txt | AC | 682 ms | 60744 KiB |
| random10.txt | AC | 455 ms | 48072 KiB |
| random11.txt | AC | 504 ms | 46248 KiB |
| random12.txt | AC | 404 ms | 46084 KiB |
| random13.txt | AC | 510 ms | 47584 KiB |
| random14.txt | AC | 655 ms | 55780 KiB |
| random15.txt | AC | 602 ms | 55340 KiB |
| random16.txt | AC | 647 ms | 54572 KiB |
| random17.txt | AC | 387 ms | 45296 KiB |
| random18.txt | AC | 674 ms | 60780 KiB |
| random19.txt | AC | 693 ms | 62944 KiB |
| random2.txt | AC | 329 ms | 37788 KiB |
| random20.txt | AC | 465 ms | 43996 KiB |
| random21.txt | AC | 631 ms | 55844 KiB |
| random22.txt | AC | 453 ms | 43336 KiB |
| random23.txt | AC | 414 ms | 46240 KiB |
| random24.txt | AC | 625 ms | 52776 KiB |
| random25.txt | AC | 175 ms | 27140 KiB |
| random26.txt | AC | 702 ms | 55648 KiB |
| random27.txt | AC | 478 ms | 47352 KiB |
| random28.txt | AC | 411 ms | 45080 KiB |
| random29.txt | AC | 364 ms | 36912 KiB |
| random3.txt | AC | 704 ms | 55180 KiB |
| random30.txt | AC | 159 ms | 27312 KiB |
| random31.txt | AC | 603 ms | 51272 KiB |
| random32.txt | AC | 704 ms | 55504 KiB |
| random33.txt | AC | 568 ms | 58972 KiB |
| random34.txt | AC | 627 ms | 57480 KiB |
| random35.txt | AC | 475 ms | 49824 KiB |
| random36.txt | AC | 660 ms | 59832 KiB |
| random37.txt | AC | 559 ms | 51984 KiB |
| random38.txt | AC | 614 ms | 55008 KiB |
| random39.txt | AC | 302 ms | 34856 KiB |
| random4.txt | AC | 579 ms | 55776 KiB |
| random5.txt | AC | 699 ms | 55756 KiB |
| random6.txt | AC | 540 ms | 51108 KiB |
| random7.txt | AC | 347 ms | 36600 KiB |
| random8.txt | AC | 592 ms | 49048 KiB |
| random9.txt | AC | 682 ms | 57184 KiB |