### Problem Description

ZLGG found a magic theory that the bigger banana the bigger banana peel .This important theory can help him make a portal in our universal. Unfortunately, making a pair of portals will cost min{T} energies. T in a path between point V and point U is the length of the longest edge in the path. There may be lots of paths between two points. Now ZLGG owned L energies and he want to know how many kind of path he could make.

### Input

There are multiple test cases. The first line of input contains three integer N, M and Q (1 < N ≤ 10,000, 0 < M ≤ 50,000, 0 < Q ≤ 10,000). N is the number of points, M is the number of edges and Q is the number of queries. Each of the next M lines contains three integers a, b, and c (1 ≤ a, b ≤ N, 0 ≤ c ≤ 10^8) describing an edge connecting the point a and b with cost c. Each of the following Q lines contain a single integer L (0 ≤ L ≤ 10^8).

### Output

Output the answer to each query on a separate line.

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

36
13
1
13
36
1
36
2
16
13

### 代码如下：

#include <bits/stdc++.h>
#define LL long long
#define N 10050
using namespace std;
struct node{
int a, b, c, i;
bool operator < (const node & A) const{
return c < A.c;
}
}d[N * 5], q[N];
int f[N], p[N], sum, ans[N], cnt[N];
int find(int x){
return x == f[x]? x: f[x] = find(f[x]);
}
int main(){
int i, j, n, m, t, a, b, c;
while(scanf("%d%d%d", &n, &m, &t) != EOF){
for(i = 1; i <= n; i++) f[i] = i;
for(i = 1; i <= m; i++) scanf("%d%d%d", &d[i].a, &d[i].b, &d[i].c);
sort(d + 1, d + i);
for(i = 1; i <= t; i++) scanf("%d", &q[i].c), q[i].i = i;
sort(q + 1, q + i);
for(i = 1; i <= t; i++) p[q[i].i] = i;
for(i = 1; i <= n; i++) cnt[i] = 1;
j = 1; sum = 0;
for(i = 1; i <= m; i++){
c = d[i].c;
while(c > q[j].c && j <= t){
ans[j++] = sum;
}
a = find(d[i].a); b = find(d[i].b);
if(a != b){
f[b] = a;
sum += cnt[a] * cnt[b];
cnt[a] += cnt[b];
}
}
while(j <= t) ans[j++] = sum;
for(i = 1; i <= t; i++) printf("%d\n", ans[p[i]]);
}
return 0;
}