CF1774E Two Chess Pieces

题目描述

# Two Chess Pieces Cirno\_9baka 有一棵包含 $n$ 个节点的树。他愿意把它与你分享,这意味着你可以对它进行一些操作。 最初,树的 $1$ 号节点上有两个棋子。对每个操作,您可以选择任意一个棋子,并将其移动到相邻节点。你需要确保两个棋子之间的距离不会超过 $d$。 给你两个序列,分别表示两个棋子需要经过的节点(可以以**任何顺序**经过)。最终,它们必须回到根节点。作为一个好奇的男孩,Cirno\_9baka 想知道最少操作次数。

输入格式

第一行包含两个整数 $n$ 和 $d$($2\le d\le n\le 2\cdot 10^5$)。 以下 $n-1$ 行的第 $i$ 行包含两个整数 $ u_i, v_i $ $ (1 \le u_i, v_i \le n) $,表示节点 $ u_i, v_i $ 之间的边。 保证这些边形成一棵树。 下一行包含一个整数 $m_1$($1\le m_1\le n$)和 $m_1$ 个整数 $a_1,a_2,\ldots,a_{m_1}$($1\le a_i\le n$,所有$a_i$都是不同的)- 第一个棋子需要经过的节点序列。 第二行包含一个整数$m_2$($1\le m_2\le n$)和 $m_2$ 个整数 $b_1,b_2,\ldots,b_{m_2}$($1\le b_i\le n$,所有$b_i$都是不同的)-第二棋子需要经过的节点序列。

输出格式

输出一个整数 - 最小操作次数。

说明/提示

In the first sample, here is one possible sequence of steps of length $ 6 $ . - The second piece moves by the route $ 1 \to 2 \to 4 \to 2 \to 1 $ . - Then, the first piece moves by the route $ 1 \to 3 \to 1 $ . In the second sample, here is one possible sequence of steps of length $ 8 $ : - The first piece moves by the route $ 1 \to 2 \to 3 $ . - Then, the second piece moves by the route $ 1 \to 2 $ . - Then, the first piece moves by the route $ 3 \to 4 \to 3 \to 2 \to 1 $ . - Then, the second piece moves by the route $ 2 \to 1 $ .