-
Notifications
You must be signed in to change notification settings - Fork 2
/
HDU-dx9-1009.cpp
108 lines (97 loc) · 1.59 KB
/
HDU-dx9-1009.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
ID: mfs6174
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
#define LL long long
const int MAXN=11000;
struct D
{
LL d,p;
bool operator <(const D &x) const
{
return d<x.d;
}
};
struct S
{
LL x,y,e;
bool operator <(const S &t) const
{
return e<t.e;
}
};
S ji[51000];
LL ff[MAXN],n,m,i,j,t,tt,k,q,l,mm;
LL fm[MAXN];
LL qr[110000];
D du[110000];
LL dui[110000];
LL cc;
void init(LL n)
{
int i;
for (i=1;i<=n;i++)
{
ff[i]=i;
fm[i]=1;
}
cc=0;
}
int cha(LL x)
{
if (ff[x]==x)
return x;
ff[x]=cha(ff[x]);
return ff[x];
}
void bing(LL x,LL y,LL z)
{
LL i,j;
i=cha(x);j=cha(y);
if (i!=j)
{
mm=mm-(fm[i]-1)*fm[i]/2-(fm[j]-1)*fm[j]/2+(fm[i]+fm[j]-1)*(fm[i]+fm[j])/2;
ff[i]=j;//总根为标志,把总根挂到另一个的总根下
fm[j]+=fm[i];
}
}
int main()
{
freopen("ti.in","r",stdin);
while (scanf("%lld%lld%lld",&n,&m,&q)!=EOF)
{
init(n);
for (i=1;i<=m;i++)
scanf("%lld%lld%lld",&ji[i].x,&ji[i].y,&ji[i].e);
for (i=1;i<=q;i++)
{
scanf("%lld",&(du[i].d));
du[i].p=i;
}
sort(&du[1],&du[q+1]);
sort(&ji[1],&ji[m+1]);
mm=0;
for (i=1,j=0;i<=q;i++)
{
while (j<=m&&ji[j].e<=du[i].d)
{
bing(ji[j].x,ji[j].y,ji[j].e);
j++;
}
qr[du[i].p]=mm;
}
for (i=1;i<=q;i++)
cout<<qr[i]<<endl;
}
return 0;
}