logo AlgoBeat OnlineJudge
登录 注册

#203406. [COCI 2017/2018 #2] ​​Usmjeri

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

题目描述

We are given a tree with N nodes denoted with different positive integers from 1 to N. Additionally, you are given M node pairs from the tree in the form of ( , ), ( , ), …, ( , ).

We need to direct each edge of the tree so that for each given node pair ( , ) there is a path from to or from to . How many different ways are there to achieve this? Since the solution can be quite large, determine it modulo .

输入格式

The first line of input contains the positive integers N and M (1 ≤ N, M ≤ ), the number of nodes in the tree and the number of given node pairs, respectively.

Each of the following N - 1 lines contains two positive integers, the labels of the nodes connected with an edge.

The of the following M lines contains two different positive integers and , the labels of the nodes from the node pair. All node pairs will be mutually different.

输出格式

You must output a single line containing the total number of different ways to direct the edges of the tree that meet the requirement from the task, modulo .

样例

样例输入 1

4 1
1 2
2 3
3 4
2 4

样例输出 1

4

样例输入 2

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

样例输出 2

8

样例输入 3

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

样例输出 3

0

数据范围与提示

In test cases worth 20% of total points, the given tree will be a chain. In other words, node i will be connected with an edge to node i + 1 for all i < N.

In additional test cases worth 40% of total points, it will hold N, M ≤ .

A tree is a graph that consists of N nodes and N - 1 edges such that there exists a path from each node to each other node.