Submission #851052
Source Code Expand
def read_numbers; gets.split.map(&:to_i); end N, = read_numbers CONNECTED = Hash.new{|h, k| h[k] = []} (N-1).times do a, b = read_numbers CONNECTED[a] << b CONNECTED[b] << a end def solve(i, from) b = w = 1 CONNECTED[i].each do |j| next if j == from bb, ww = solve(j, i) b *= ww w *= (bb+ww) end return [b, w] end b, w = solve(1, nil) p((b + w) % (10**9+7))
Submission Info
Submission Time | |
---|---|
Task | D - 塗り絵 |
User | yhara |
Language | Ruby (2.3.3) |
Score | 100 |
Code Size | 412 Byte |
Status | AC |
Exec Time | 640 ms |
Memory | 23804 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 | 16 ms | 1788 KB |
001.txt | AC | 18 ms | 1788 KB |
002.txt | AC | 502 ms | 20476 KB |
003.txt | AC | 615 ms | 21628 KB |
004.txt | AC | 407 ms | 16124 KB |
005.txt | AC | 630 ms | 23548 KB |
006.txt | AC | 555 ms | 21500 KB |
007.txt | AC | 603 ms | 23804 KB |
008.txt | AC | 433 ms | 18300 KB |
009.txt | AC | 606 ms | 21884 KB |
010.txt | AC | 436 ms | 18044 KB |
011.txt | AC | 600 ms | 20988 KB |
012.txt | AC | 349 ms | 12540 KB |
013.txt | AC | 602 ms | 23164 KB |
014.txt | AC | 282 ms | 12156 KB |
015.txt | AC | 640 ms | 23548 KB |
016.txt | AC | 372 ms | 12668 KB |
017.txt | AC | 603 ms | 21628 KB |
018.txt | AC | 117 ms | 6012 KB |
019.txt | AC | 606 ms | 23292 KB |
020.txt | AC | 70 ms | 3708 KB |
021.txt | AC | 605 ms | 21244 KB |