#P4757. Maximum Edge-Disjoint Parades

    ID: 18001 Type: Default 1000ms 256MiB

Maximum Edge-Disjoint Parades

Maximum Edge-Disjoint Parades

In the City of Eternal Festivities there are \(n\) street junctions and \(n-1\) bidirectional streets forming a tree. Between every two junctions there is exactly one (direct or indirect) path. Moreover, no junction is an endpoint for more than 10 streets. Every 13th of September (the 256th day of the year), the citizens plan to organize \(m\) parades. The \(i\)th parade starts at junction \(u_i\) and ends at \(v_i\), following the unique path between them.

As the mayor, you decree that no two parades are allowed to share the same street (i.e. each street may be used by at most one parade), although parades may have common junctions (or even endpoints). Your task is to select as many parades as possible while obeying this safety regulation.

Input Format: The input begins with two integers \(n\) and \(m\) denoting the number of junctions and parades. Then \(n-1\) lines follow each containing two integers \(u\) and \(v\) which indicate a bidirectional street connecting junctions \(u\) and \(v\). Finally, \(m\) lines follow, each containing two integers \(u_i\) and \(v_i\) that describe the starting and ending junctions of the \(i\)th parade.

Output Format: Output a single integer, the maximum number of parades that can be organized such that no street is used by more than one parade.

inputFormat

The input begins with two integers \(n\) and \(m\) on one line. \(n\) is the number of junctions and \(m\) is the number of parades.

Then follow \(n-1\) lines, each containing two integers \(u\) and \(v\) representing a bidirectional street between junctions \(u\) and \(v\).

Then \(m\) lines follow, each containing two integers \(u_i\) and \(v_i\) indicating the start and end junction of the \(i\)th parade.

You may assume that the junctions are numbered from 1 to \(n\) and that the given streets form a tree. Also, no junction is incident to more than 10 streets.

outputFormat

Output a single integer: the maximum number of parades that can be organized such that no street is used by more than one parade.

sample

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