Codeforces Round #597 (Div. 2)D(最小生成树)
/*每个点自己建立一座发电站相当于向超级源点连一条长度为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(最小生成树)的更多相关文章
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树
题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...
- 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 ...
- 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 ...
- Codeforces Round #597 (Div. 2) C. Constanze's Machine
链接: https://codeforces.com/contest/1245/problem/C 题意: Constanze is the smartest girl in her village ...
- 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 ...
- Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring
链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...
- Codeforces Round #597 (Div. 2)
A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...
- 计算a^b==a+b在(l,r)的对数Codeforces Round #597 (Div. 2)
题:https://codeforces.com/contest/1245/problem/F 分析:转化为:求区间内满足a&b==0的对数(解释见代码) ///求满足a&b==0在区 ...
- 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 ...
随机推荐
- vue实现隔行换色,下拉菜单控制隔行换色的颜色
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 松软科技课堂:jQuery 语法
jQuery 语法 jQuery 语法是为 HTML 元素的选取编制的,可以对元素执行某些操作. 基础语法是:$(selector).action() 美元符号定义 jQuery 选择符(select ...
- Entity Framework 简介
Entity Framework Entity Framework 的全称为 ADO.NET Entity Framework,简称 EF. 1.与 ADO.NET 的关系 Entity F ...
- 【译】写个好的 CLI 程序
写个好的 CLI 程序 Write a Good CLI Program 译文 原文链接:https://qiita.com/tigercosmos/items/678f39b1209e60843cc ...
- AtCoder Beginner Contest 144
https://atcoder.jp/contests/abc144/tasks/abc144_c #include<bits/stdc++.h> using namespace std; ...
- centos修改静态Ip地址
centos修改静态Ip地址 待办 昨天待办 https://blog.csdn.net/johnnycode/article/details/40624403 centos修改静态ip地址
- codeforce F - Three Paths on a Tree
F. Three Paths on a Tree time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- ASP学习笔记1
一.变量 1.1 声明变量 dim name name="Donald Duck" response.write("My name is: " & na ...
- 【网易官方】极客战记(codecombat)攻略-地牢-囚犯
关卡连接: https://codecombat.163.com/play/level/the-prisoner 解放囚犯,你会得到盟友. 简介 敬请期待! 默认代码 # 释放囚犯,击败守卫并夺取宝石 ...
- Bugku-CTF分析篇-手机热点(有一天皓宝宝没了流量只好手机来共享,顺便又从手机发了点小秘密到电脑,你能找到它吗?)
手机热点 httppan.baidu.coms1cwwdVC 有一天皓宝宝没了流量只好手机来共享,顺便又从手机发了点小秘密到电脑,你能找到它吗? 题目来源:第七季极客大挑战