Submission #783705
Source Code Expand
MOD = 10**9 + 7 n = gets.chomp.to_i a, b = [], [] h = Hash.new {|hsh, key| hsh[key] = []} (n-1).times do |i| a[i], b[i] = gets.chomp.split(" ").map(&:to_i) h[a[i]] << b[i] h[b[i]] << a[i] end def dp(n, p, hash) tmp = 1 tmpW = 1 hash[n].each do |i| if i == p next end t = dp(i, n, hash) tmpW *= t[0] tmp *= t[1] end return [(tmp + tmpW) % MOD, tmpW % MOD] end puts dp(1, 0, h)[0]
Submission Info
Submission Time | |
---|---|
Task | D - 塗り絵 |
User | jjfifjfjfifj |
Language | Ruby (2.3.3) |
Score | 100 |
Code Size | 446 Byte |
Status | AC |
Exec Time | 709 ms |
Memory | 19196 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
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 | 1788 KB |
001.txt | AC | 18 ms | 1788 KB |
002.txt | AC | 572 ms | 16892 KB |
003.txt | AC | 709 ms | 19068 KB |
004.txt | AC | 461 ms | 14588 KB |
005.txt | AC | 692 ms | 19196 KB |
006.txt | AC | 656 ms | 18300 KB |
007.txt | AC | 692 ms | 19068 KB |
008.txt | AC | 484 ms | 16124 KB |
009.txt | AC | 697 ms | 18940 KB |
010.txt | AC | 507 ms | 16252 KB |
011.txt | AC | 698 ms | 18940 KB |
012.txt | AC | 396 ms | 11644 KB |
013.txt | AC | 672 ms | 19068 KB |
014.txt | AC | 318 ms | 10492 KB |
015.txt | AC | 705 ms | 19068 KB |
016.txt | AC | 416 ms | 12028 KB |
017.txt | AC | 675 ms | 18940 KB |
018.txt | AC | 131 ms | 5628 KB |
019.txt | AC | 703 ms | 19068 KB |
020.txt | AC | 77 ms | 3708 KB |
021.txt | AC | 706 ms | 19068 KB |