Codeforces Round 366 (Div. 1)
E
Iron Man
Codeforces
3300
原题
← D→
翻译中…

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

翻译中…

Tony has $*m*$ suits. There's a special plan for each suit. The $*i*$-th suit will appear at the moment of time $*t*_{*i*}$ in the junction $*v*_{*i*}$, and will move to junction $*u*_{*i*}$ using the shortest path between $*v*_{*i*}$ and $*u*_{*i*}$ with the speed $*c*_{*i*}$ roads per second (passing a junctions takes no time), and vanishing immediately when arriving at $*u*_{*i*}$ (if it reaches $*u*_{*i*}$ in time $*q*$, it's available there at moment $*q*$, but not in further moments). Also, suits move continuously (for example if $*v*_{*i*} ≠ *u*_{*i*}$, at time image it's in the middle of a road. Please note that if $*v*_{*i*} = *u*_{*i*}$ it means the suit will be at junction number $*v*_{*i*}$ only at moment $*t*_{*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).

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 100 000$) — the number of junctions and the number of suits respectively.

翻译中…

The next $*n* - 1$ lines contain the roads descriptions. Each line contains two integers $*a*_{*i*}$ and $*b*_{*i*}$ — endpoints of the $*i*$-th road ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$, $*a*_{*i*} ≠ *b*_{*i*}$).

翻译中…

The next $*m*$ lines contain the suit descriptions. The $*i*$-th of them contains four integers $*t*_{*i*}$, $*c*_{*i*}$, $*v*_{*i*}$ and $*u*_{*i*}$ ($0 ≤ *t*_{*i*} ≤ 10 000, 1 ≤ *c*_{*i*} ≤ 10 000$, $1 ≤ *v*_{*i*}, *u*_{*i*} ≤ *n*$), meaning the $*i*$-th suit will appear at moment of time $*t*_{*i*}$ at the junction $*v*_{*i*}$ and will move to the junction $*u*_{*i*}$ with a speed $*c*_{*i*}$ roads per second.

翻译中…

Output

翻译中…

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 $10^{ - 6}$.

翻译中…

样例

Input #1
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
Output #1
27.3
InputCopy OutputCopy
Input #2
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
Output #2
-1
InputCopy OutputCopy
题目信息
题号
704E
时间限制
5 s
内存限制
256 MB
标签
数据结构
计算几何
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。