시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
5 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 13 | 6 | 3 | 100.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.
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.
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
18 32 18 160
University > KAIST > 2022 KAIST 12th ICPC Mock Competition K번
Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 4: KAIST+KOI Contest, Grand Prix of Korea K번