포럼
문제 COCI00459

Usmjeri

설명

We are given a tree with \(N\) nodes denoted with different positive integers from 1 to \(N\).
1
Additionally, you are given \(M\) node pairs from the tree in the form of (a_{1}, b_{1}), (a_{2}, b_{2}), ..., (a_{M},
\(b_{M}\)).
We need to direct each edge of the tree so that for each given node pair (a_{i}, \(b_{i}\)) there is a
path from \(a_{i}\) to \(b_{i}\) or from \(b_{i}\) to \(a_{i}\). How many different ways are there to achieve this?
Since the solution can be quite large, determine it modulo \(10^{9} + 7\).

제약

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 \le 5 \cdot 10^{3}\).

입력 형식

The first line of input contains the positive integers \(N\) and \(M\) (\(1 \le N\), \(M \le 3 \cdot 10^{5}\)), 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 \(i^{th}\) of the following \(M\) lines contains two different positive integers \(a_{i}\) and \(b_{i}\), the labels of
the nodes from the \(i^{th}\) 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 \(10^{9} + 7\).

예제 1
입력
4 1
1 2
2 3
3 4
2 4
출력
4
예제 2
입력
7 2
1 2
1 3
4 2
2 5
6 5
5 7
1 7
2 6
출력
8
예제 3
입력
4 3
1 2
1 3
1 4
2 3
2 4
3 4
출력
0
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2017/2018 Contest 2

평가 및 의견

Usmjeri

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Usmjeri

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8