#P1344E. Train Tracks

Train Tracks

Description

That's right. I'm a Purdue student, and I shamelessly wrote a problem about trains.

There are nn stations and mm trains. The stations are connected by n1n-1 one-directional railroads that form a tree rooted at station 11. All railroads are pointed in the direction from the root station 11 to the leaves. A railroad connects a station uu to a station vv, and has a distance dd, meaning it takes dd time to travel from uu to vv. Each station with at least one outgoing railroad has a switch that determines the child station an incoming train will be directed toward. For example, it might look like this:

Here, stations 11 and 33 have switches directed toward stations 22 and 44, respectively.

Initially, no trains are at any station. Train ii will enter station 11 at time tit_i. Every unit of time, starting at time 11, the following two steps happen:

  1. You can switch at most one station to point to a different child station. A switch change takes effect before step 22.
  2. For every train that is on a station uu, it is directed toward the station vv indicated by uu's switch. So, if the railroad from uu to vv has distance dd, the train will enter station vv in dd units of time from now.

Every train has a destination station sis_i. When it enters sis_i, it will stop there permanently. If at some point the train is going in the wrong direction, so that it will never be able to reach sis_i no matter where the switches point, it will immediately explode.

Find the latest possible time of the first explosion if you change switches optimally, or determine that you can direct every train to its destination so that no explosion occurs. Also, find the minimum number of times you need to change a switch to achieve this.

The first line contains two integers nn and mm (1n,m1051\le n,m\le 10^5) — the number of stations and trains, respectively.

The next n1n-1 lines describe the railroads. The ii-th line contains three integers u,v,du,v,d (1u,vn1\le u,v\le n, 1d1091\le d\le 10^9), denoting a railroad from station uu to station vv with distance dd. It is guaranteed that the railroads form a tree rooted at station 11. The switch of a station uu is initially directed towards the last outgoing railroad from uu that appears in the input.

The next mm lines describe the trains. The ii-th line contains two integers si,tis_i,t_i (1sin1\le s_i\le n, 1t1<t2<<tm1091\le t_1<t_2<\cdots<t_m\le 10^9) — the destination station and the time the ii-th train enters station 11, respectively.

Output two integers: the latest possible time of the first explosion (or 1-1 if it is possible to never have an explosion) and the minimum number of switch changes to achieve it.

Input

The first line contains two integers nn and mm (1n,m1051\le n,m\le 10^5) — the number of stations and trains, respectively.

The next n1n-1 lines describe the railroads. The ii-th line contains three integers u,v,du,v,d (1u,vn1\le u,v\le n, 1d1091\le d\le 10^9), denoting a railroad from station uu to station vv with distance dd. It is guaranteed that the railroads form a tree rooted at station 11. The switch of a station uu is initially directed towards the last outgoing railroad from uu that appears in the input.

The next mm lines describe the trains. The ii-th line contains two integers si,tis_i,t_i (1sin1\le s_i\le n, 1t1<t2<<tm1091\le t_1<t_2<\cdots<t_m\le 10^9) — the destination station and the time the ii-th train enters station 11, respectively.

Output

Output two integers: the latest possible time of the first explosion (or 1-1 if it is possible to never have an explosion) and the minimum number of switch changes to achieve it.

Sample Input 1

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

Sample Output 1

-1 6

Sample Input 2

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

Sample Output 2

4 0

Sample Input 3

11 6
1 2 1
1 3 2
3 4 1
3 5 2
5 6 1
5 7 2
7 8 1
7 9 2
9 10 1
9 11 1
2 1
8 3
6 5
10 7
4 9
2 11

Sample Output 3

11 4

Note

For the first test, here's an example timeline:

  • At time 11, train 11 enters station 11. We switch station 11 to point to station 22. Train 11 is directed to station 22.
  • At time 22, train 22 enters station 11, and train 11 enters station 22, where it stops permanently. We switch station 11 to point to station 33. Train 22 is directed to station 33.
  • At time 44, train 22 enters station 33. We switch station 33 to point to station 44. Train 22 is directed to station 44.
  • At time 55, train 22 enters station 44, where it stops permanently.
  • At time 66, train 33 enters station 11. We switch station 11 to point to station 22. Train 33 is directed to station 22.
  • At time 77, train 33 enters station 22, where it stops permanently. We switch station 33 to point to station 55.
  • At time 1010, train 44 enters station 11. We switch station 11 to point to station 33. Train 44 is directed to station 33.
  • At time 1212, train 44 enters station 33. Train 44 is directed to station 55.
  • At time 1515, train 44 enters station 55, where it stops permanently.

For the second test, we switch nothing. At time 44, train 22 is directed to station 55 and train 44 is directed to station 33. They both explode. It is impossible to prevent an explosion by time 44.

For the third test, denote a switch change by (uv,t)(u\to v,t) if we make station uu point to station vv at time tt. One solution is to make these 44 switch changes: (12,1)(1\to 2,1),(13,2)(1\to 3,2),(78,5)(7\to 8,5),(56,8)(5\to 6,8). At time 1111, trains 44,55, and 66 explode. It is impossible to prevent an explosion by time 1111.