Under construction

Still being built. Things may change

Watchdogs

Time limit5sMemory limit1024 MB

Summary
Given a tree and mouse paths, find the fewest vertices that include at least one middle vertex of every path.
Level

Medium6 of 10

Topics
Tree, Dynamic programming
Solved
No attempts yet

Problem

In Kocourkov, a small town surrounded by hills and woods, mice have become a problem. The town was peaceful for years, known for its cozy pubs and friendly people. Then the mice arrived. They are smart and quick, and they seem to be everywhere at once. They have taken over the town's favorite pubs, running through the rafters, nibbling on crumbs, and causing a lot of trouble.

Kocourkov has NN places and exactly N−1N - 1 roads, and you can reach any place from any other place by using the roads. Each road connects a pair of places.

The town council met in the largest pub, U Nacpané Myši. They noticed that the mice run across the city in a specific pattern. Each mouse has exactly two lairs, and it runs only between them. Each lair is in one of the places. The council also observed that a mouse is vulnerable about halfway along its usual path. Formally, if a mouse has lairs at places AA and BB, then the mouse is vulnerable at place CC if and only if ∣d(C,A)−d(C,B)∣≤1|d(C, A)-d(C, B)| \le 1 and CC is on the path from AA to BB. Here d(X,Y)d(X, Y) is the number of roads on the path from XX to YY. A mouse may be vulnerable at several places, and it may also be vulnerable at its own lair.

The town will place watchcats around the city. A watchcat can get rid of a mouse if the watchcat sits at a place where the mouse is vulnerable. One watchcat can get rid of any number of mice. Watchcats are lazy. Each one sits at its chosen place and never moves.

Watchcats are expensive, so the town council wants to buy as few as possible. Help them with this task.

Input

The first line contains two integers NN and KK (2≤N≤1052 \le N \le 10^5, 0≤K≤1050 \le K \le 10^5), the number of places and the number of mice.

Each of the next N−1N - 1 lines contains two integers UU and VV (0≤U,V≤N−10 \le U, V \le N - 1), meaning that places UU and VV are connected by a direct road.

Each of the next KK lines contains two integers PP and QQ (0≤P,Q≤N−10 \le P, Q \le N - 1), meaning that a mouse has lairs at places PP and QQ. It is guaranteed that P≠QP \ne Q.

Output

Print a single integer, the minimum number of watchcats needed so that every mouse is eventually caught.

Examples1

  1. Example 1

    Input
    7 5
    0 1
    0 2
    2 5
    1 4
    4 6
    1 3
    1 6
    1 3
    3 2
    1 5
    2 5
    
    Expected output
    3