OI Problems   关于

#pr5kba. Iron Man

时间限制:5 s       空间限制:256 MiB       标签: 图论 树链剖分 重链剖分 计算几何 扫描线 CodeForces 

算法难度等级:6       思维难度等级:6       实现难度等级:5

本题来源于:Codeforces Round 366 (Div. 1) Problem E


Tony Stark 在玩游戏。在一个 nn 个点的树上,Tony Stark 放置了 mm 个鸡贼。每个鸡贼有四个整数参数 ti, ci, vi, uit_i,\ c_i,\ v_i,\ u_i ,表示这个鸡贼会在 tit_i 时刻出现在点 viv_i,并以每时刻 cic_i 条边的速度向 uiu_i匀速移动,到达 uiu_i 点时立刻消失


(注意,如果一个鸡贼的 ui=viu_i=v_i 那么它会在 tit_i 时刻出现,此时如果这个点有其它鸡贼一样会发生爆炸)

Tony Stark 想知道最早有鸡贼爆炸的时刻。如果自始至终都没发生爆炸输出 -1

如果你的答案和标准答案的绝对或相对误差不超过 10610^{-6} 那么被视为正确。


Tony Stark is playing a game with his suits (they have auto-pilot now). He lives in Malibu. Malibu has nn junctions numbered from 11 to nn, connected with n1n-1 roads. One can get from a junction to any other junction using these roads (graph of Malibu forms a tree).

Tony has mm suits. There's a special plan for each suit. The ii-th suit will appear at the moment of time tit_{i} in the junction viv_{i}, and will move to junction uiu_{i} using the shortest path between viv_{i} and uiu_{i} with the speed cic_{i} roads per second (passing a junctions takes no time), and vanishing immediately when arriving at uiu_{i} (if it reaches uiu_{i} in time qq , it's available there at moment qq , but not in further moments). Also, suits move continuously (for example if viuiv_{i}\neq u_{i}, at time ti+12cit_i+\dfrac 1{2c_i} it's in the middle of a road. Please note that if vi=uiv_{i}=u_{i} it means the suit will be at junction number viv_{i} only at moment tit_{i} and then it vanishes.

An explosion happens if at any moment of time two suits share the same exact location (it may be in a junction or somewhere on a road; while appearing, vanishing or moving).

Your task is to tell Tony the moment of the the first explosion (if there will be any).


The first line of the input contains two integers nn and mm (1<=n,m<=1000001<=n,m<=100000) — the number of junctions and the number of suits respectively.

The next n1n-1 lines contain the roads descriptions. Each line contains two integers aia_{i} and bib_{i} — endpoints of the ii-th road (1<=ai,bi<=n1<=a_{i},b_{i}<=n, aibia_{i}\neq b_{i}).

The next mm lines contain the suit descriptions. The ii-th of them contains four integers tit_{i}, cic_{i}, viv_{i} and uiu_{i} (0<=ti<=10000,1<=ci<=100000<=t_{i}<=10000,1<=c_{i}<=10000, 1<=vi,ui<=n1<=v_{i},u_{i}<=n), meaning the ii-th suit will appear at moment of time tit_{i} at the junction viv_{i} and will move to the junction uiu_{i} with a speed cic_{i} roads per second.


If there would be no explosions at all, print -1 in the first and only line of output.

Otherwise print the moment of the first explosion.

Your answer will be considered correct if its relative or absolute error doesn't exceed 10610^{-6} .

6 4
2 5
6 5
3 6
4 6
4 1
27 6 1 3
9 5 1 6
27 4 3 4
11 29 2 6
6 4
3 1
4 5
6 4
6 1
2 6
16 4 4 5
13 20 6 2
3 16 4 5
28 5 3 5