记录编号 |
58238 |
评测结果 |
AAAAAAAAAA |
题目名称 |
威尼斯旅行 |
最终得分 |
100 |
用户昵称 |
feng |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
3.330 s |
提交时间 |
2013-04-18 18:34:13 |
内存使用 |
9.70 MiB |
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
struct ed{
int x,y,v;
}edge[200002];
struct qq{
int k,num;
}qu[200002];
int father[200002];
long long ans[200002];
int Size[200002];
int hash[200002];
int n,m,q;
int find(int x){
return father[x]==x?x:father[x]=find(father[x]);
}
bool cmp1(ed a,ed b){
return a.v<b.v;
}
bool cmp2(qq a,qq b){
return a.k<b.k;
}
void init(){
freopen("tripa.in","r",stdin);
freopen("tripa.out","w",stdout);
scanf("%d%d%d",&n,&m,&q);
for (int i=1;i<=m;i++)
scanf("%d%d%d",&edge[i].x,&edge[i].y,&edge[i].v);
sort(edge+1,edge+m+1,cmp1);
for (int i=1;i<=q;i++){
scanf("%d",&qu[i].k);
qu[i].num=i;
}
sort(qu+1,qu+q+1,cmp2);
for (int i=1;i<=q;i++)
hash[qu[i].num]=i;
}
long long cul(int x){
long long s=x;
return s*(s-1)/2;
}
void work(){
int o,k,x,y,fx,fy;
long long tmpx,tmpy,tmp=0;
o=1;
for (int i=1;i<=n;i++)
father[i]=i;
for (int i=1;i<=n;i++)
Size[i]=1;
for (int i=1;i<=q;i++){
k=qu[i].k;
while (edge[o].v<=k && o<=m){
x=edge[o].x;
y=edge[o].y;
fx=find(x);
fy=find(y);
if (fx!=fy){
tmpx=cul(Size[fx]);
tmpy=cul(Size[fy]);
tmp+=cul(Size[fx]+Size[fy])-tmpx-tmpy;
father[fx]=father[fy];
Size[fy]+=Size[fx];
Size[fx]=0;
}
o++;
}
ans[i]=tmp;
}
for (int i=1;i<=q;i++)
cout<<ans[hash[i]]<<endl;
}
int main()
{
init();
work();
return 0;
}