1387:搭配购买(buy)
发布时间
阅读量:
阅读量
1387:组合购买(buy)
时间限制: 1000 ms 内存限制: 65536 KB
【题目描述
//示例代码
#include <iostream>
#include <cstdio>
using namespace std;
const int N=10005;
int n,m,w;
int p,f[N],c[N],d[N],val[N];
int u,v;
// 并查集的查找函数,返回x号元素所在集合的根
int find(int x){
// 如果当前元素为其所在集合的根,则返回该元素
if(f[x]==x) return f[x];
// 否则通过递归寻找该元素所在集合的根并路径压缩
return f[x]=find(f[x]);
}
int main(){
scanf("%d %d %d",&n,&m,&w);
// 输入n个云朵的属性之后,初始化并查集f,并对每个云朵作为单独的集合分别记录代价和价值
for(int i=1;i<=n;i++){
s
全部评论 (0)
还没有任何评论哟~
