Submission #26470241
Source Code Expand
Copy
N,M,K = gets.split.map(&:to_i)A = gets.split.map(&:to_i)U2V = Array.new(N+1){[]}E = (N-1).times.map{|e|gets.split.map(&:to_i).tap{|u,v|U2V[u]<<[v,e]U2V[v]<<[u,e]}}Fs = [nil]*(N-1)F = lambda{|e,c|Fs[e] = A.each_cons(2).count{|u,v| c[u]!=c[v] }}C = Array.new(N+1){1<<_1}D = U2V.map(&:size)Q = (1..N).select{|u| D[u]<2 }while u = Q.popc = C[u]U2V[u].each{|v,e|next if Fs[e]
N,M,K = gets.split.map(&:to_i) A = gets.split.map(&:to_i) U2V = Array.new(N+1){[]} E = (N-1).times.map{|e| gets.split.map(&:to_i).tap{|u,v| U2V[u]<<[v,e] U2V[v]<<[u,e] } } Fs = [nil]*(N-1) F = lambda{|e,c| Fs[e] = A.each_cons(2).count{|u,v| c[u]!=c[v] } } C = Array.new(N+1){1<<_1} D = U2V.map(&:size) Q = (1..N).select{|u| D[u]<2 } while u = Q.pop c = C[u] U2V[u].each{|v,e| next if Fs[e] F[e,c] C[v] |= c Q << v if 1==D[v]-=1 } end # R+B = Fi.sum # R-B = K # # R+R = Fi.sum+K P = 998244353 Fz,Fi = Fs.partition{_1<1} Z = Fi.size RR = Fi.sum+K R = RR/2 S = [{0=>1}]*(Z+1) #warn [Fz,Fi].inspect p(R+R!=RR ? 0 : (1..Z).sum{|k| S.shift ss = Hash.new 0 (Z-k).downto(0){|i| dr = Fi[i] S[i].each{|r,s| next if R<r+dr ss[r+dr] += s ss[r+dr] %= P } S[i] = ss.dup } #warn [k,ss[R],S].inspect next ss[R] }*2.pow(Fz.size,P)%P)
Submission Info
Submission Time | |
---|---|
Task | E - Red and Blue Tree |
User | ds14050 |
Language | Ruby (2.7.1) |
Score | 0 |
Code Size | 917 Byte |
Status | WA |
Exec Time | 2208 ms |
Memory | 100136 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
All | hand_01.txt, hand_02.txt, hand_03.txt, 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, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
hand_01.txt | AC | 58 ms | 14340 KB |
hand_02.txt | AC | 56 ms | 14236 KB |
hand_03.txt | AC | 58 ms | 14228 KB |
random_01.txt | TLE | 2044 ms | 92404 KB |
random_02.txt | AC | 1782 ms | 97564 KB |
random_03.txt | AC | 887 ms | 59188 KB |
random_04.txt | AC | 59 ms | 14248 KB |
random_05.txt | AC | 1123 ms | 76796 KB |
random_06.txt | AC | 929 ms | 92220 KB |
random_07.txt | AC | 1476 ms | 100136 KB |
random_08.txt | AC | 101 ms | 20788 KB |
random_09.txt | TLE | 2208 ms | 93288 KB |
random_10.txt | AC | 877 ms | 99032 KB |
random_11.txt | AC | 123 ms | 24468 KB |
random_12.txt | AC | 139 ms | 25572 KB |
random_13.txt | TLE | 2208 ms | 99172 KB |
random_14.txt | AC | 80 ms | 14536 KB |
random_15.txt | AC | 87 ms | 14432 KB |
random_16.txt | AC | 64 ms | 14516 KB |
random_17.txt | AC | 1260 ms | 86628 KB |
random_18.txt | AC | 62 ms | 14216 KB |
random_19.txt | AC | 68 ms | 14544 KB |
random_20.txt | AC | 58 ms | 14356 KB |
random_21.txt | AC | 93 ms | 14588 KB |
random_22.txt | AC | 87 ms | 14648 KB |
random_23.txt | AC | 67 ms | 14556 KB |
random_24.txt | AC | 259 ms | 38840 KB |
random_25.txt | AC | 90 ms | 14628 KB |
random_26.txt | AC | 237 ms | 43120 KB |
random_27.txt | AC | 386 ms | 41356 KB |
random_28.txt | AC | 183 ms | 33960 KB |
random_29.txt | AC | 309 ms | 19196 KB |
random_30.txt | WA | 184 ms | 14876 KB |
random_31.txt | AC | 285 ms | 19100 KB |
random_32.txt | AC | 320 ms | 17564 KB |
random_33.txt | WA | 186 ms | 14876 KB |
random_34.txt | AC | 92 ms | 14584 KB |
random_35.txt | WA | 55 ms | 14268 KB |
random_36.txt | WA | 89 ms | 14636 KB |
random_37.txt | AC | 90 ms | 14408 KB |
sample_01.txt | AC | 57 ms | 14204 KB |
sample_02.txt | AC | 58 ms | 14164 KB |
sample_03.txt | AC | 58 ms | 14208 KB |
sample_04.txt | AC | 58 ms | 14340 KB |