社区讨论

玄学做法拿了64分

P14362[CSP-S 2025] 道路修复参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mhixogk2
此快照首次捕获于
2025/11/03 17:24
4 个月前
此快照最后确认于
2025/11/08 07:50
4 个月前
查看原帖
求比较小的hack数据 玄关
代码:
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,cnt[20],kw[20],tot,ans,mov[20],f[110010],kkw[20][110010];
struct edge{
	int a,b,w;
};
bool operator <(const edge x,const edge y){
	return (x.w>y.w)||(x.w==y.w&&x.a>n&&cnt[x.a-n]==1)||(x.w==y.w&&y.a>n&&cnt[y.a-n]==0);
}
priority_queue<edge,vector<edge> > q;
int getf(int x){
	if(f[x]==x)
		return x;
	return f[x]=getf(f[x]);
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		int a,b,w;
		cin>>a>>b>>w;
		q.push((edge){a,b,w});
	}
	for(int i=1;i<=k;i++){
		cin>>kw[i];
		int a=n+i,b=1,w;
		for(;b<=n;cin>>w,kkw[i][b]=w,w+=kw[i],q.push((edge){a,b,w}),b++);
	}
	for(int i=1;i<=n+k;f[i]=i,i++);
	for(;tot<n+k-1;){
		edge qq=q.top();
		q.pop();
		int fa=getf(qq.a),fb=getf(qq.b);
		if(fa==fb)
			continue;
		tot++;
		ans+=qq.w;
		f[fa]=fb;
		if(qq.a>n){
			if(!cnt[qq.a-n]){
				mov[qq.a-n]=qq.w;
				for(int i=1;i<=n;q.push((edge){qq.a,i,kkw[qq.a-n][i]}),i++);
			}
			cnt[qq.a-n]++;
		}
	}
	for(int i=1;i<=k;i++)
		if(cnt[i]==1)
			ans-=mov[i];	
	cout<<ans;
	return 0;
} 

回复

0 条回复,欢迎继续交流。

正在加载回复...