/*每个点自己建立一座发电站相当于向超级源点连一条长度为c[i]的边,连电线即为(k[i]+k[j])*两点间曼哈顿距离,跑最小生成树(prim适用于稠密图,kruscal适用于稀疏图)*/

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int fa[2007];
int x[2007],y[2007];
int c[2007],k[2007];
long long m[2007][2007];
vector<pair<long long,pair<int,int> > >edge;
vector<int>ans_point;
vector<pair<int,int> >ans_edge;
int fi(int x){
return fa[x]==x?x:fa[x]=fi(fa[x]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=1;i<=n;++i)
cin>>x[i]>>y[i];
for(int i=1;i<=n;++i)
cin>>c[i];
for(int i=1;i<=n;++i)
cin>>k[i];
for(int i=1;i<=n;++i){
m[0][i]=c[i];
fa[i]=i;
edge.push_back({c[i],make_pair(0,i)});
}
for(int i=1;i<=n;++i){
for(int j=i+1;j<=n;++j){
long long tamp=1ll*(k[i]+k[j])*(abs(x[i]-x[j])+abs(y[i]-y[j]));
edge.push_back({tamp,make_pair(i,j)});
}
}
sort(edge.begin(),edge.end());
long long ans=0;
for(int i=0;i<edge.size();++i){
long long tamp=edge[i].first;
int x=edge[i].second.first;
int y=edge[i].second.second;
if(fi(x)==fi(y))
continue;
ans+=tamp;
if(!x)
ans_point.push_back(y);
else
ans_edge.push_back({x,y});
fa[fi(y)]=x;
}
cout<<ans<<"\n";
cout<<ans_point.size()<<"\n";
for(int i=0;i<ans_point.size();++i)
cout<<ans_point[i]<<" ";
cout<<"\n";
cout<<ans_edge.size()<<"\n";
for(int i=0;i<ans_edge.size();++i)
cout<<ans_edge[i].first<<" "<<ans_edge[i].second<<"\n";
return 0;
}

Codeforces Round #597 (Div. 2)D(最小生成树)的更多相关文章

  1. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树

    题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...

  2. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 最小生成树

    D. Shichikuji and Power Grid</centerD.> Shichikuji is the new resident deity of the South Blac ...

  3. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid

    链接: https://codeforces.com/contest/1245/problem/D 题意: Shichikuji is the new resident deity of the So ...

  4. Codeforces Round #597 (Div. 2) C. Constanze's Machine

    链接: https://codeforces.com/contest/1245/problem/C 题意: Constanze is the smartest girl in her village ...

  5. Codeforces Round #597 (Div. 2) B. Restricted RPS

    链接: https://codeforces.com/contest/1245/problem/B 题意: Let n be a positive integer. Let a,b,c be nonn ...

  6. Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring

    链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...

  7. Codeforces Round #597 (Div. 2)

    A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...

  8. 计算a^b==a+b在(l,r)的对数Codeforces Round #597 (Div. 2)

    题:https://codeforces.com/contest/1245/problem/F 分析:转化为:求区间内满足a&b==0的对数(解释见代码) ///求满足a&b==0在区 ...

  9. Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp

    F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...

随机推荐

  1. jquery-validation.js验证插件使用详解

    jquery-validation 使用 一.用前必备 官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: ...

  2. DOM盒模型和位置 client offset scroll 和滚动的关系

    DOM盒模型和位置 client offset scroll 和滚动的关系 概览 在dom里面有几个描述盒子位置信息的值, pading border margin width height clie ...

  3. Java-POJ1005-I Think I Need a Houseboat

    盗用的翻译,哈哈哈!白嫖就完事了. 题目: 密西西比河岸某处陆地因为河水侵蚀,每年陆地面积都在减少,每年减少50平方英里,减少的陆地面积呈半圆形,即该半圆形面积以每年50平方英里的速度增长.在第一年初 ...

  4. 12day echo {1..100} << 三剑客命令

    04. 直接编辑文件命令方法 a 如何直接在文件中添加单行内容 echo "oldboy" >>/oldboy/oldboy.txt 补充: echo命令用法说明: 0 ...

  5. 3.创建springboot程序

    有两种方式创建springboot项目 第一种方式:在官网上创建(基本上不用) Spring官方提供了非常方便的工具 Spring Initializr:https://start.spring.io ...

  6. HTML学习(5)标题、水平线、注释

    HTML 标题 标题(Heading)是通过 <h1> - <h6> 标签进行定义的. <h1> 定义最大的标题. <h6> 定义最小的标题. 注: 浏 ...

  7. JSP读取数据库二进制图片并显示

    用JSP从数据库中读取二进制图片并显示在网页上 环境mysql+tomcat: 先在mysql下建立如下的表. 并存储了二进制图像(二进制格式存储图片可以参考我的另一篇博客:https://www.c ...

  8. java &&和&与逻辑运算区别

    二者都表示与运算,同真为真,遇假即假 && 具有短路功能,前面为false后面不在预算直接表达式为false; &还可以用作位运算符,当&操作符两边的表达式不是 boo ...

  9. servlet中Request与response使用

    服务器根据请求自动创建传入HttpServletRequest对象和HttpServletResponse对象 @Override protected void service(HttpServlet ...

  10. Multisim 如何添加文本 如何编辑文本字体

    1.在Multisim中如何添加文本 方法1)Place -> Text 方法2)Ctrl+T 2.如何修改字体的大小及颜色