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

27568번 - Branch Manager 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 1024 MB92423355.932%

문제

You are managing a transportation network of one-way roads between cities. People travel through the transportation network one by one in order all starting from the same city, and each person waits for the person before them to stop moving before starting. The people follow a simple algorithm until they reach their destination: they will look at all the outgoing roads from the current city, and choose the one that leads to the city with the smallest label. A person will stop when they either reach their destination, or reach a city with no outgoing roads. If at any point someone fails to reach their destination, the rest of the people still waiting in line will leave.

Before each person enters the transportation network, you can permanently close down any subset of roads to guarantee they reach their destination. The roads that you choose to close down will not be available for future people.

There are $n$ cities, labeled from 1ドル$ to $n$. There are $n-1$ directed roads, and each road will always be from a lower labeled city to a higher labeled one. The network will form a rooted tree with city 1ドル$ as the root. There are $m$ people that want to travel through the network. Each person starts from city 1ドル,ドル and has a specific destination city $d$ in mind. These people will line up in the given order. What is the maximum number of people you can route correctly to their destination if you close roads optimally?

입력

The first line of input contains two integers $n$ and $m$ (2ドル \le n,m \le 2 \times 10^5$), where $n$ is the number of cities and $m$ is the number of people.

Each of the next $n-1$ lines contains two integers $a$ and $b$ (1ドル \le a < b \le n$), denoting a directed road from city $a$ to $b$. These roads will describe a rooted tree with city 1ドル$ as the root.

Each of the next $m$ lines contains a single integer $d$ (2ドル \le d \le n$), denoting the destination city of the next person in line.

출력

Output a single integer, which is the maximum number of people you can route to the correct destination.

제한

예제 입력 1

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

예제 출력 1

5

예제 입력 2

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

예제 출력 2

1

힌트

출처

ICPC > Regionals > North America > Mid-Atlantic Regional > 2022 Mid-Atlantic USA Regional Contest > Division 1 L번

ICPC > Regionals > North America > South Central USA Regional > 2022 South Central USA Regional Contest > Division 1 L번

ICPC > Regionals > North America > Southeast USA Regional > 2022 Southeast USA Regional Programming Contest > Division 1 L번

ICPC > Regionals > North America > Mid-Atlantic Regional > 2022 Mid-Atlantic USA Regional Contest > Division 2 L번

ICPC > Regionals > North America > South Central USA Regional > 2022 South Central USA Regional Contest > Division 2 L번

ICPC > Regionals > North America > Southeast USA Regional > 2022 Southeast USA Regional Programming Contest > Division 2 L번

ICPC > Regionals > North America > Mid-Central Regional > 2022 Mid-Central USA Regional Contest I번

ICPC > Regionals > North America > Pacific Northwest Regional > 2022 ICPC Pacific Northwest Region > Division 1 H번

ICPC > Regionals > North America > Rocky Mountain Regional > 2022 Rocky Mountain Regional Contest H번

  • 문제를 만든 사람: Lewin Gan
(追記) (追記ここまで)

출처

대학교 대회

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

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