#P3363. Cool loves jiaoyi

Cool loves jiaoyi

Description

Cool’s trading partners form a tree.

For each trade, there is a start and an end. The path from the start to the end on the tree is called the trade chain. All trading partners (nodes) on the trade chain join this trade, and the cost of the trade equals the number of trading partners on the chain.

Now there are mm trades. Cool will designate kk trades such that there exists a mysterious trading partner who participates in all these kk trades, and he wants to minimize the maximum difference of costs among these kk trades (i.e., minimize max cost - min cost).

Input Format

The input consists of several lines.

  • The first line contains three integers n,m,kn, m, k, representing the number of trading partners, the number of trades, and the designated kk.
  • Each of the next n1n-1 lines contains two integers u,vu, v, indicating that trading partners uu and vv are connected in the trading tree.
  • Each of the next mm lines contains two integers s,ts, t, representing the start and end of a trade (the start and end may coincide).

Output Format

Output a single integer, the minimal possible value of the maximum cost difference among the designated trades. If no such set of kk trades exists, output 1-1.

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

Hint

Constraints

1n5×104,1km104.1\leq n\leq 5\times 10^4, 1\leq k\leq m\leq 10^4.

Sample Explanation

Choose trades 1,2,31, 2, 3. Trading partner 11 participates in all three trades, and the three costs are 3,4,43, 4, 4. Their maximum cost difference is 434-3. This is optimal.

Translated by ChatGPT 5