Submission #690200


Source Code Expand

# encoding: utf-8
@m = 1000000000+7
n = gets.chomp.to_i

@a = Array.new(n)
0.step(n-1, 1) do |i|
  @a[i] = Array.new
end
0.step(n-2, 1) do |i|
  ai,bi = gets.chomp.split(" ").map(&:to_i)
  @a[ai-1].push (bi-1)
  @a[bi-1].push (ai-1)
end

def bt(c, p)
  w = b = 1
  for v in @a[c]
    if v != p
      wc,bc = bt(v, c)
      w = w*(wc+bc)%@m
      b = b*wc%@m
    end
  end
  return [w, b]
end

r = (bt(0,-1).inject(:+))%@m
puts r

Submission Info

Submission Time
Task D - 塗り絵
User wood23
Language Ruby (2.3.3)
Score 100
Code Size 457 Byte
Status AC
Exec Time 494 ms
Memory 11644 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 22
Set Name Test Cases
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt
Case Name Status Exec Time Memory
000.txt AC 17 ms 1788 KB
001.txt AC 17 ms 1788 KB
002.txt AC 354 ms 10620 KB
003.txt AC 494 ms 11516 KB
004.txt AC 309 ms 9724 KB
005.txt AC 449 ms 11644 KB
006.txt AC 411 ms 11260 KB
007.txt AC 444 ms 11516 KB
008.txt AC 321 ms 10236 KB
009.txt AC 445 ms 11516 KB
010.txt AC 337 ms 10236 KB
011.txt AC 443 ms 11388 KB
012.txt AC 269 ms 7420 KB
013.txt AC 456 ms 11516 KB
014.txt AC 223 ms 7164 KB
015.txt AC 444 ms 11644 KB
016.txt AC 291 ms 9596 KB
017.txt AC 445 ms 11388 KB
018.txt AC 94 ms 4092 KB
019.txt AC 445 ms 11516 KB
020.txt AC 58 ms 2940 KB
021.txt AC 445 ms 11516 KB