Logo
(追記) (追記ここまで)

25838번 - Safe Logging 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB71114.286%

문제

Consider a tree (not necessarily a binary tree). We will use the term neighbor to refer to the parent and children of a node, i.e., nodes with direct connection to the node. Some of the nodes in the tree have a log. All logs have two colors: Red at the top-half and Black at the bottom-half.

Our strong friend, Lumber-Knight (LK), needs to cut all these logs in half. When a log is cut, the Red (top) part falls into a neighbor but the neighbor cannot contain a Black part. This means each node will eventually contain only one Black log or several (zero or more) Red logs. Note that the Black logs do not move from node to node. Note also that when a Red log falls into a neighbor, it does not move anymore.

Lumber-Knight, besides being strong, is also very stylish. He does not want any node with Black log to have two (or more) neighbors with Red logs. Your job is to determine all different ways the Red logs can be moved to (cut and fall into) neighbors to meet the LK’s style. Since the number of ways can be quite large, output the number of ways modulo 1,000,000,007.

Given a tree description and locations of the logs, determine the number of ways in which LumberKnight can cut the logs and move the Red logs into neighbors such that no node with Black log has two (or more) neighbors with Red logs.

입력

The first input line contains an integer, n (1 ≤ n ≤ 100,000), representing the number of nodes in the tree (assume the tree nodes are numbered 1 to n, with 1 being the tree root). Each of the following n – 1 input lines contains two integers, ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), representing a direct connection between two nodes.

Following the tree description will be an integer, m (1 ≤ m ≤ n), representing the number of tree nodes with a log. The following input line contains m distinct integers (i.e., no duplicates), representing the tree nodes that contain a log.

출력

Print a single integer representing the number of ways the m logs can be cut and the Red part moved to a neighbor such that no node with a Black log has two (or more) neighbors with Red part. If it is not possible to accomplish the task, print 0 (zero).

Two cutting sequences are considered different if there is a node with different contents in the two sequences, e.g., the node is empty in one case and contains Red log(s) in the other case.

제한

예제 입력 1

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

예제 출력 1

1

예제 입력 2

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

예제 출력 2

2

힌트

출처

University > University of Central Florida > 2020 Local Programming Contest (Final Round) 11번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /