| 比赛 |
26暑假集训模拟赛3 |
评测结果 |
AAAAAAAAAAATTTTTTTTA |
| 题目名称 |
城市建设 |
最终得分 |
60 |
| 用户昵称 |
ChenBp |
运行时间 |
42.356 s |
| 代码语言 |
C++ |
内存使用 |
3.95 MiB |
| 提交时间 |
2026-07-06 10:15:06 |
显示代码纯文本
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
const int N=2e4+4,M=5e4+4;
struct edge {
int u,v,w,id;
} e[M*2];
int fa[N];
int f[M];
int fi(int x) {
if(fa[x]!=x) return fa[x]=fi(fa[x]);
return x;
}
int main() {
freopen("hnoi2010_city.in","r",stdin);
freopen("hnoi2010_city.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n,m,q;
cin>>n>>m>>q;
for(int i=1; i<=m; i++) {
cin>>e[i].u>>e[i].v>>e[i].w;
e[i].id=i;
}
sort(e+1,e+1+m,[](edge x,edge y) {
return x.w<y.w;
});
while(q--) {
int k,d;
cin>>k>>d;
for(int i=1; i<=m; i++) {
f[e[i].id]=i;
}
e[f[k]].w=d;
sort(e+1,e+1+m,[](edge x,edge y) {
return x.w<y.w;
});
for(int i=1; i<=n; i++) {
fa[i]=i;
}
long long ans=0;
for(int i=1; i<=m; i++) {
int fu=fi(e[i].u),fv=fi(e[i].v);
if(fu!=fv){
ans+=e[i].w;
fa[fu]=fv;
}
}
cout<<ans<<'\n';
}
return 0;
}