Submission #690647


Source Code Expand

N = gets.to_i
@bridge = {}
@dp = Array.new(10010)
@dp2 = Array.new(10010)

def f(p, x)
  child = @bridge[x].reject { |i| i == p }

  child.each { |j| f(x, j) } 

  prod = 1
  child.each { |j| prod *= @dp[j] }

  @dp2[x] = prod % 1000000007
  
  prod2 = 1
  child.each { |j| prod2 *= @dp2[j] }
  @dp[x] = (@dp2[x] + prod2) % 1000000007
end

$<.read.split(/\n/).map do |s|
  a, b = s.split.map(&:to_i)
  a -=1
  b -=1
  @bridge[a] ||= Array.new
  @bridge[a] << b;
  @bridge[b] ||= Array.new
  @bridge[b] << a;
end

f(-1, 0)
puts @dp[0]

Submission Info

Submission Time
Task D - 塗り絵
User hoi
Language Ruby (2.3.3)
Score 100
Code Size 564 Byte
Status AC
Exec Time 682 ms
Memory 27900 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 19 ms 1916 KB
001.txt AC 19 ms 1916 KB
002.txt AC 523 ms 24700 KB
003.txt AC 680 ms 27772 KB
004.txt AC 441 ms 22140 KB
005.txt AC 682 ms 27900 KB
006.txt AC 622 ms 26748 KB
007.txt AC 673 ms 27900 KB
008.txt AC 486 ms 23548 KB
009.txt AC 670 ms 27772 KB
010.txt AC 493 ms 23292 KB
011.txt AC 677 ms 27644 KB
012.txt AC 401 ms 18940 KB
013.txt AC 671 ms 27900 KB
014.txt AC 314 ms 14844 KB
015.txt AC 677 ms 27900 KB
016.txt AC 417 ms 19836 KB
017.txt AC 673 ms 27772 KB
018.txt AC 131 ms 6780 KB
019.txt AC 669 ms 27900 KB
020.txt AC 77 ms 4988 KB
021.txt AC 676 ms 27772 KB