| 比赛 |
26暑假集训模拟赛3 |
评测结果 |
AAAAAAAAAAATTTTTTTTA |
| 题目名称 |
城市建设 |
最终得分 |
60 |
| 用户昵称 |
彭欣越 |
运行时间 |
45.139 s |
| 代码语言 |
C++ |
内存使用 |
4.20 MiB |
| 提交时间 |
2026-07-06 11:02:03 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;
int n,m,q,f[N];
struct node {
int u,v;
ll w;
}a[N],b[N];
bool cmp (node x,node y) {
return x.w<y.w;
}
int find (int x) {
if (f[x]==x) return x;
return f[x]=find(f[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);
cin >> n >> m >> q;
for (int i=1;i<=m;i++) cin >> a[i].u >> a[i].v >> a[i].w;
while (q--) {
int x,y;
ll ans=0;
cin >> x >> y;
a[x].w=y;
for (int i=1;i<=m;i++) b[i]=a[i];
sort(b+1,b+1+m,cmp);
for (int i=1;i<=n;i++) f[i]=i;
for (int i=1;i<=m;i++) {
int u=b[i].u,v=b[i].v;
if (find(u)!=find(v)) {
f[find(u)]=find(v);
ans+=b[i].w;
}
}
cout << ans <<endl;
}
return 0;
}