Two Paths

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

You are given a tree TT consisting of NN vertices. Each edge has a positive integer weight. The weight of a path PP in TT is defined as the sum of weights of edges in PP, denoted by W(P)W(P).

You are given a total of QQ queries, each containing two vertices uu, vv, and two integers AA and BB. For each query, you are to find two simple paths P_1P\_1 and P_2P\_2 in TT satisfying these requirements.

  • P_1P\_1 and P_2P\_2 doesn’t share a vertex.
  • P_1P\_1 starts from uu, and P_2P\_2 starts from vv.
  • Among all P_1P\_1 and P_2P\_2 satisfying the conditions above, the value of A×W(P_1)+B×W(P_2)A\times W(P\_1) +B\times W(P\_2) should be maximized.

You should output the value of A×W(P_1)+B×W(P_2)A\times W(P\_1) +B\times W(P\_2) for each query.

입력

The first line contains two space-separated integers NN and QQ.

Each of the following N1N-1 lines contains three space-separated integers uu, vv, ww. This means that there is an edge in TT, connecting vertices uu and vv with weight ww.

Each of the following QQ lines contains four space-separated integers uu, vv, AA, BB, denoting a single query.

출력

For each query, output the maximum possible value of A×W(P_1)+B×W(P_2)A\times W(P\_1) +B\times W(P\_2). The answers should be separated by newlines.

제한

  • 2N200,0002\le N\le 200\\, 000
  • 1Q500,0001\le Q\le 500\\, 000
  • 1u\<vN1\le u\<v\le N for both edges and queries
  • 1w10,0001\le w\le 10\\, 000
  • 1A,B2×1091\le A,B\le 2\times 10^9