Logo
(追記) (追記ここまで)

25737번 - Two Paths 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB (추가 메모리 없음)1685100.000%

문제

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

You are given a total of $Q$ queries, each containing two vertices $u,ドル $v,ドル and two integers $A$ and $B$. For each query, you are to find two simple paths $P_1$ and $P_2$ in $T$ satisfying these requirements.

  • $P_1$ and $P_2$ doesn’t share a vertex.
  • $P_1$ starts from $u,ドル and $P_2$ starts from $v$.
  • Among all $P_1$ and $P_2$ satisfying the conditions above, the value of $A\times W(P_1) +B\times W(P_2)$ should be maximized.

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

입력

The first line contains two space-separated integers $N$ and $Q$.

Each of the following $N-1$ lines contains three space-separated integers $u,ドル $v,ドル $w$. This means that there is an edge in $T,ドル connecting vertices $u$ and $v$ with weight $w$.

Each of the following $Q$ lines contains four space-separated integers $u,ドル $v,ドル $A,ドル $B,ドル denoting a single query.

출력

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

제한

  • 2ドル\le N\le 200,円 000$
  • 1ドル\le Q\le 500,円 000$
  • 1ドル\le u<v\le N$ for both edges and queries
  • 1ドル\le w\le 10,円 000$
  • 1ドル\le A,B\le 2\times 10^9$

예제 입력 1

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

예제 출력 1

18
32
18
160

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2022 KAIST 12th ICPC Mock Competition K번

Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 4: KAIST+KOI Contest, Grand Prix of Korea K번

채점 및 기타 정보

  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /