Wanna Hangout?

5

6 votes
Problem

Param has a huge crush on a girl in his college. But this girl shows her interest only to the boys who can solve tough graph questions(don't know why though). Now she ask him a qute interesting question which is as follows:->

You are given a weigthed graph of N nodes having N1 edges such that you can reach any node from any other node.

Now you have been asked to find the total no. of distinct paths (path from a to b is same as from b to a) such that the maximum weigth of edges on each of these paths is less than or equal to X.

Since he is busy trying on other girls, help him solve this one.

Note:-> Weigths are distinct.

Input

First line contains N (no. of edges).

Next N1 line contains three integers u,v,w representing an undirected edge from u to v having weigth of w.

Next line contains Q (no. of queries).

Next Q line contains an integer X.

Output

Print Q integers. In each line print answer to ith  query.

Constraints

2 <= N <= 105

1 <= Q <= 105

1 <= u <= N

1 <= v <= N

1 <= w <= 109

1 <= X <= 109

NOTE:-> It contains partial marking as follows:->

10 points for N , Q <= 103

Sample Input
6
2 3 1
3 1 9
1 5 2
3 4 5
2 6 8
3
1
4
5
Sample Output
1
2
4
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?