Submission #851589
Source Code Expand
N = gets.chomp.to_i AB = (N-1).times.map{ gets.chomp.split(" ").map(&:to_i) } M = [[]] N.times.map{ M << [] } AB.each{|a,b| M[a] << b; M[b] << a } MOD = 10 ** 9 + 7 def draw(from, n) if M[n].size == 1 b, w = [1, 1] else b, w = M[n].map{|to| next if from == to to_b, to_w = draw(n, to) [to_w, to_w + to_b] }.compact.inject([1,1]){|r, bw| r = [r[0] * bw[0], r[1] * bw[1]] r } end return [b, w] end start = M.map.with_index.max{|a, b| a[0].size <=> b[0].size }[1] b, w = draw(0, start) puts (b + w) % MOD
Submission Info
Submission Time | |
---|---|
Task | D - 塗り絵 |
User | nari |
Language | Ruby (2.3.3) |
Score | 100 |
Code Size | 584 Byte |
Status | AC |
Exec Time | 704 ms |
Memory | 26716 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 | 17 ms | 1788 KB |
001.txt | AC | 18 ms | 1788 KB |
002.txt | AC | 577 ms | 20988 KB |
003.txt | AC | 667 ms | 21980 KB |
004.txt | AC | 448 ms | 19828 KB |
005.txt | AC | 680 ms | 23420 KB |
006.txt | AC | 591 ms | 21276 KB |
007.txt | AC | 650 ms | 22008 KB |
008.txt | AC | 486 ms | 21024 KB |
009.txt | AC | 657 ms | 24036 KB |
010.txt | AC | 493 ms | 19652 KB |
011.txt | AC | 636 ms | 22012 KB |
012.txt | AC | 398 ms | 18220 KB |
013.txt | AC | 648 ms | 22748 KB |
014.txt | AC | 314 ms | 12812 KB |
015.txt | AC | 651 ms | 23288 KB |
016.txt | AC | 424 ms | 20376 KB |
017.txt | AC | 704 ms | 26716 KB |
018.txt | AC | 129 ms | 6640 KB |
019.txt | AC | 644 ms | 20580 KB |
020.txt | AC | 77 ms | 4348 KB |
021.txt | AC | 661 ms | 22524 KB |