Victorious Coloring (Easy Version)

시간 제한3초메모리 제한2048 MB

요약
가중치 트리에서 각 질의 l마다 최소 승리 색칠 비용이 l 이상이 되도록 정점 가중치 합의 최솟값을 구한다.
난이도

어려움10점 중 9점

유형
트리, 동적 계획법, 그리디, 수학
정답자
아직 제출이 없습니다

문제

This is the easy version of the problem. The difference between the versions is that in this version, q≤10q \le 10. You can hack only if you solved all versions of this problem.

You are given a tree with nn vertices, where each vertex is numbered from 11 to nn. Each edge is assigned a positive integer weight w_1,w_2,…,w_n−1w\_1, w\_2, \ldots, w\_{n-1} as well.

A victorious coloring is a coloring of each vertex into two colors: red and yellow, where there should be at least one vertex colored in red (corresponding to the symbol of team T1).

Suppose that there is a nonnegative integer weight x_1,x_2,…,x_nx\_1, x\_2, \ldots, x\_n assigned to each vertex. The cost of the victorious coloring is defined as the sum of the weights of all red vertices, plus the sum of the weights of all edges that connect vertices of different colors (between red and yellow). We define f(\[x_1,x_2,…,x_n])f(\[x\_1, x\_2, \ldots, x\_n]) as the minimum possible cost for all victorious colorings.

Gumayusi considered the problem of computing f(\[x_1,x_2,…,x_n])f(\[x\_1, x\_2, \ldots, x\_n]), given the sequence x_1,x_2,…,x_nx\_1, x\_2, \ldots, x\_n. However, this problem was too easy for him, so he devised a variation: Given an integer ll, find a sequence of nonnegative integer vertex weights \[x_1,x_2,…,x_n]\[x\_1, x\_2, \ldots, x\_n] such that f(\[x_1,x_2,…,x_n])≥lf(\[x\_1, x\_2, \ldots, x\_n]) \ge l and the total sum ∑_i=1nx_i\sum\_{i=1}^n x\_i is minimized.

Gumayusi was satisfied, but there was a serious issue --- this problem doesn't have any queries, which is a necessary component for any problem that isn't bad. So, he added queries to this problem. For each ll given as a query, you must find the corresponding minimum possible sum of vertex weights.

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line contains an integer nn (2≤n≤250,0002 \le n \le 250\\,000) --- the number of vertices.

The following n−1n-1 lines contain three integers u_iu\_i, v_iv\_i, w_iw\_i (1≤u_i,v_i≤n,1≤w_i≤109,u_i≠v_i1 \le u\_i, v\_i \leq n, 1 \le w\_i \le 10^9, u\_i \neq v\_i) --- indicating an edge connecting the vertices u_iu\_i and v_iv\_i with weight w_iw\_i.

It is guaranteed that the edges form a tree.

The next line contains an integer qq (1≤q≤101 \le q \le 10) --- the number of queries.

The following qq lines contain a single integer l_il\_i (1≤l_i≤1091 \leq l\_i \leq 10^9) --- the parameters of the ii-th query.

It is guaranteed that the sum of nn over all test cases does not exceed 250,000250\\,000.

Note that there is no explicit upper bound on the sum of qq.

출력

For each of the qq queries, output the answer separated by lines.

힌트

The following list shows the possible optimal assignments for each query in the first test case:

  • \[18,24,2,26,18]\[18,24,2,26,18]
  • \[22,28,6,30,22]\[22,28,6,30,22]
  • \[4,7,0,9,1]\[4,7,0,9,1]
  • \[7,13,0,15,7]\[7,13,0,15,7]
  • \[13,19,0,21,13]\[13,19,0,21,13]

예제1

  1. 예제 1

    입력
    2
    5
    3 5 10
    2 3 4
    3 1 10
    3 4 2
    5
    28
    32
    11
    17
    23
    2
    1 2 3
    1
    1
    
    예상 출력
    88
    108
    21
    42
    66
    1