logo AlgoBeat OnlineJudge
登录 注册

#206120. [NEERC 2017] Laminar Family

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

While studying combinatorial optimization, Lucas came across the notion of laminar set family. A subset family of some set is called laminar if and only if it does not contain an empty set and for any two distinct sets A , it is correct that either or or .

As an experienced problem setter Lucas always tries to apply each new piece of knowledge he gets as an idea for a programming competition problem. An area of his scientific interests covers recognition problems that usually sound like Given some weird combinatorial property, check if the given structure satisfies it.

Lucas believes that the perfect programming competition problem should contain a cactus a tree in it. Trying to put together laminar sets and trees into a recognition problem, he finally came up with the following problem: given an undirected tree on vertices and a family of sets, where consists of all vertices belonging to the simple path between some two vertices and of the tree, check if the family is a laminar family. Note that in this case , and each .

As you can see, Lucas had succeeded in suggesting this problem to the programming contest. Now it is up to you to solve it.

输入格式

The first line of the input contains two integers and -- the number of vertices in the tree and the number of elements in a family .

Next lines describe the tree structure. In the i-th line there are two integers and -- the indices of the vertices that are connected by the i-th edge of the tree.

Next lines describe the sets forming the family . In the i-th line there are two integers and , such that consists of all vertices belonging to the simple path between vertices and in the tree (including and

输出格式

Output the only word Yes or No depending on whether or not the given set family is laminar.

样例

样例输入 1

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

样例输出 1

No

样例输入 2

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

样例输出 2

Yes

数据范围与提示

Time limit: 2 s, Memory limit: 512 MB.