1819 四通八达的树


Submit solution

Points: 100
Time limit: 2.0s
Memory limit: 32M

Problem types
Allowed languages
C, C++, Java, Python

Description

一棵有n个节点的无根树,包含n-1条无向边,每个点都能达到其余的n-1个点。现在给你一棵包含n个点的树,和一些查询(A, B),你需要输出一条路径,从A达到B并且经过最少的点。这条路径明显是唯一的哦。

Input

多组数据。每组数据第一行两个整数N和Q,表示树几点个数和查询数目(1<=N, Q<=100)。 然后是N-1行,每行表示树的一条边。 然后是Q行,每行表示一个查询(A, B)。

Output

首先输出case数,然后每条路径要输出path数,接着是路径。具体看样例。

Sample

Input

3 2
1 2
3 2
3 3
1 3

5 3
1 5
2 5
1 4
4 3
3 4
5 4
4 2

Output

Case #1:
Path 1: 3
Path 2: 1 2 3
Case #2:
Path 1: 3 4
Path 2: 5 1 4
Path 3: 4 1 5 2

Source: zjut_DD


Comments

There are no comments at the moment.