time limit per test : 2 seconds
memory limit per test : 256 megabytes
You are given a tree (a connected undirected graph without cycles) of n n n vertices. Each of the n − 1 n−1 n−1 edges of the tree is colored in either black or red.
You are also given an integer k k k . Consider sequences of k k k vertices. Let’s call a sequence [ a 1 , a 2 , … , a k ] [a_1,a_2,…,a_k] [a1,a2,…,ak]
good if it satisfies the following criterion:
We will walk a path (possibly visiting same edge/vertex multiple times) on the tree, starting from a 1 a_1 a1 and ending at a k a_k ak.
Start at a 1 a_1 a1, then go to a 2 a_2 a2 using the shortest path between a 1 a_1 a1 and a 2 a_2 a2, then go to a 3 a_3 a