COCI '17 Contest 2 #5 Usmjeri

View as PDF

Submit solution


Points: 17
Time limit: 1.0s
Memory limit: 256M

Problem types

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 (a1,b1),(a2,b2),,(aM,bM).

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

Input Specification

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

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

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

Output Specification

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 109+7.

Scoring

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,M5103.

Sample Input 1

Copy
4 1
1 2
2 3
3 4
2 4

Sample Output 1

Copy
4

Sample Input 2

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

Sample Output 2

Copy
8

Sample Input 3

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

Sample Output 3

Copy
0

Comments

There are no comments at the moment.