提出 #18053537
ソースコード 拡げる
class Array
def ^ other # Both of self and other must be unique and sorted.
i,*a = j = t = 0
ix,jx,v = self.size,other.size
begin
(i+=1; j+=1) while (v = other[j]) && self[i] == v
a.concat self[i...i+=t] if 0 < t = v ? self[i,ix].bsearch_index{ v<=_1 }||ix-i : ix-i
a.concat other[j...j+=t] if 0 < t = (v = self[i]) ? other[j,jx].bsearch_index{ v<=_1 }||jx-j : jx-j
end while v
return a
end
end
N,Q = gets.split.map(&:to_i)
ChildrenOfV = Array.new(N+1){ {} }
ParentOfV = [nil]*(N+1)
ColorOfV = Array.new(N+1){ [] }
EdgeOfV = [nil]*(N+1)
ColorOfE = [nil]*(N-1)
Edges = (N-1).times.map{
a,b = gets.split.map(&:to_i)
ChildrenOfV[a][b] = b
ChildrenOfV[b][a] = a
next a,b
}
Colors = Q.times.map{|z|
u,v,c = gets.split.map(&:to_i)
ColorOfV[u] << z
ColorOfV[v] << z
next c
}
Colors << 0
i,子を認知する親の行列 = -1,[N]
子を認知する親の行列.concat ChildrenOfV[p=子を認知する親の行列[i]].each{|c,|
ParentOfV[c] = ChildrenOfV[c].delete p
}.keys while (i+=1) < 子を認知する親の行列.size
Edges.each_with_index{|(p,c),i|
EdgeOfV[ParentOfV[c] == p ? c : p] = i
}
子を認知する親の行列.shift
子を認知する親の行列.reverse_each{|p|
ColorOfV[p] = ChildrenOfV[p].map{|u,| _,ColorOfV[u] = ColorOfV[u],nil; _ }.inject(ColorOfV[p],:^)
ColorOfE[EdgeOfV[p]] = Colors[ColorOfV[p].max||-1]
ChildrenOfV[p] = nil
}
Kernel.p *ColorOfE
提出情報
コンパイルエラー
./Main.rb:53: warning: `*' interpreted as argument prefix
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 6 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| random_01.txt | AC | 63 ms | 14288 KiB |
| random_02.txt | AC | 1491 ms | 92036 KiB |
| random_03.txt | AC | 563 ms | 59680 KiB |
| random_04.txt | AC | 153 ms | 19112 KiB |
| random_05.txt | AC | 317 ms | 42408 KiB |
| random_06.txt | AC | 80 ms | 17044 KiB |
| random_07.txt | AC | 1029 ms | 44748 KiB |
| random_08.txt | AC | 347 ms | 36192 KiB |
| random_09.txt | AC | 820 ms | 66836 KiB |
| random_10.txt | AC | 838 ms | 45356 KiB |
| random_11.txt | AC | 62 ms | 14284 KiB |
| random_12.txt | AC | 1589 ms | 77172 KiB |
| random_13.txt | AC | 458 ms | 54824 KiB |
| random_14.txt | AC | 1398 ms | 64216 KiB |
| random_15.txt | AC | 981 ms | 55660 KiB |
| random_16.txt | AC | 334 ms | 42552 KiB |
| random_17.txt | TLE | 4416 ms | 210696 KiB |
| random_18.txt | AC | 304 ms | 72920 KiB |
| random_19.txt | TLE | 4415 ms | 202604 KiB |
| random_20.txt | AC | 1024 ms | 83688 KiB |
| random_21.txt | AC | 138 ms | 23072 KiB |
| random_22.txt | AC | 1065 ms | 56712 KiB |
| random_23.txt | AC | 572 ms | 121480 KiB |
| random_24.txt | AC | 337 ms | 77720 KiB |
| random_25.txt | AC | 1512 ms | 183736 KiB |
| random_26.txt | AC | 191 ms | 31380 KiB |
| random_27.txt | AC | 3035 ms | 183968 KiB |
| random_28.txt | TLE | 4416 ms | 189548 KiB |
| random_29.txt | AC | 1589 ms | 189172 KiB |
| random_30.txt | AC | 2176 ms | 185540 KiB |
| sample_01.txt | AC | 59 ms | 14332 KiB |
| sample_02.txt | AC | 61 ms | 14232 KiB |