| INOI 2025 |
|---|
| Finished |
You are given a weighted, undirected tree of $$$N$$$ nodes. $$$d(u,v)$$$ is defined as the minimum sum of weights of the edges that lie on the unique, simple path between nodes $$$u$$$ and $$$v$$$ on the tree.
You need to answer $$$Q$$$ queries. In each query, you are given an integer $$$K$$$. Determine if there exists a pair of nodes $$$(u,v)$$$ that satisfy the following conditions:
There are multiple test cases in each file, and thus you will be given an input parameter $$$T$$$, denoting that you have to solve $$$T$$$ test cases.
The first line of input contains a single integer $$$T$$$ — the number of input test cases.
The first line of each test case contains two space-separated integers $$$N$$$ and $$$Q$$$ — the number of nodes in the tree and the number of queries to be answered.
The next $$$N-1$$$ lines describe the edges of the tree. The $$$i$$$-th of these $$$N-1$$$ lines contains three space-separated integers $$$u_i, v_i, w_i$$$, denoting an undirected edge between nodes $$$u_i$$$ and $$$v_i$$$ with weight $$$w_i$$$.
The next $$$Q$$$ lines describe the queries. The $$$i$$$-th of these lines contains a single integer $$$K_i$$$ — the value of $$$K$$$ for the $$$i$$$-th query.
For each test case, output a binary string $$$S$$$ of length $$$Q$$$ where $$$S_i$$$ is $$$1$$$ if and only if the answer to the $$$i$$$-th query is positive, i.e. there exists a pair of nodes $$$(u, v)$$$ such that $$$K_i \le d(u, v) \le 2 \cdot K_i$$$ (and $$$S_i$$$ is $$$0$$$ otherwise).
Constraints
It is guaranteed that
Subtasks
The term Line means that the edges follow the constraint $$$u_i = i, v_i = (i + 1)$$$ for all $$$1 \le i \le N - 1$$$.
The term Star means that the edges follow the constraint $$$u_i = 1, v_i = (i + 1)$$$ for all $$$1 \le i \le N - 1$$$.
34 51 2 52 3 23 4 203719285 71 3 92 4 33 2 802 5 25102030401001201403 21 2 100000000000001 3 100000000000001800000000000021000000000000
11100 0101100 10
Test Case 1 : We can find valid vertices $$$u$$$ and $$$v$$$ in the first $$$3$$$ queries in the following way:
It can be proven that there is no valid pair $$$(u, v)$$$ for the last $$$2$$$ queries with $$$K = 9$$$ and $$$28$$$.
| Name |
|---|


