Table Football

Time limit: 3s Memory limit: 512MB Input: Output:

Bland Ice is one of the strongest table football player, and he is going around the world playing tournaments to gain the most ranking points possible.

Bland Ice freezing his opponents\text{Bland Ice freezing his opponents}

The world is made up of NN cities, connected by N1N-1 bidirectional roads. Moving along a single road always take one day, and it is possible to move from any city to any other using the roads. Ice is currently in city 00.

Ice knows that there will be MM tournaments in the upcoming days, the ii-th of which is in city XiX_i and TiT_i days in the future. Note that Ice can take part in a tournament on the very same day he arrives in its city.

Task

Ice wants to take part in as many tournaments as possible, however he is too busy practicing his "Chinese shot" to plan which tournaments to take part in and he is therefore asking for your help!

What's the maximum number of tournaments he can take part in?

Input data

The input file consists of N+MN+M lines, containing:

  • Line 11: two integers NN and MM.
  • Line 2+i2+i (0i<N10 \leq i < N - 1): two integers AiA_i and BiB_i.
  • Line 1+N+i1+N+i (0i<M0 \leq i < M): two integers XiX_i and TiT_i.

Output data

The output file must contain a single line containing the answer to the problem.

Constraints and clarifications

  • 2N1052 \leq N \leq 10^5.
  • 0M1050 \leq M \leq 10^5.
  • 0Ai,Bi<N0 \leq A_i, B_i < N for each 0i<N0 \leq i < N.
  • AiBiA_i \neq B_i for each 0i<N0 \leq i < N.
  • 0Ti1090 \leq T_i \leq 10^9 for each 0i<M0 \leq i < M.
  • 0Xi<N0 \leq X_i < N for each 0i<M0 \leq i < M.
  • Each pair of city is connected by some roads.
  • There are no two tournaments on the same day in the same city.
# Score Constraints
1 0 Examples
2 15 N,M200N, M \leq 200
3 15 N5 000N \leq 5 \ 000, M2 000M \leq 2 \ 000
4 20 M2 000M \leq 2 \ 000
5 10 Ai=iA_i=i and Bi=i+1B_i=i+1 for each 0i<N10 \leq i < N - 1
6 10 Ai=i/2A_i=\lfloor i / 2 \rfloor and Bi=i+1B_i=i+1 for each 0i<N10 \leq i < N - 1
7 30 No additional restrictions

Example

stdin

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

stdout

2

Explanation

The figure shows the first sample case}. In this case, Bland Ice can move to city 22 and remain there forever, taking part in 22 tournaments.
It can be shows that in no way Ice can take part in 33 tournaments.

Log in or sign up to be able to send submissions!