5294: Gas Station

内存限制:256 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

ZYT loves driving. One day he found some islands, and wanted to go on a tour.

These n islands are connected  by n−1 bi-directed roads. The ith road connects island ui, vi , and takes wi liter(s) of gasoline to pass. And on each island there is a gas station, which can add at most ai liter(s) of gasoline to his car.

ZYT has q plans, the ith is that:
  1. He will start from xi, and has di liter(s) of gasoline initially.
  2. There's an island pi he does not like to pass in this plan.


For each plan, he wants to know how many different islands he can reach in this plan(including xi). We say he can reach the island y if and if only there exists a available simple path starts from xi and ends at y, and he always has at least 0 liter of gasoline during the whole tour.

A simple path is a path that passes each island at most once.

输入

The first line of input contains two integers n, q — number of islands, number of tour plans.

Then n−1 lines ,each line containing three integers ui, vi, wi, describing a road.

Then a line with n integers a1,a2,⋯,an — the gas stations' fuel limits.

Last q lines, each contains three integers xi, di, pi, describing a tour plan.

输出

Output q lines — the number of reachable islands in each plan.

样例输入 复制

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

样例输出 复制

4
1
4
3
3

提示

It's guaranteed that n100000,q100000,1ai,wi109,1xi,ui,vin,0 di≤1014,pi ≠ xi.