传送门:CodeForces-1245D
思路分析
建立超级点与每个点连边,边权为$c_i$
每个点两两连边,跑一遍最小生成树就行了
样例输入
3
2 3
1 1
3 2
3 2 3
3 2 3
样例输出
8
3
1 2 3
0
AC代码
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
bool IOerror=0;
inline char nc() {
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if(p1==pend) {
p1=buf;
pend=buf+fread(buf,1,BUF_SIZE,stdin);
if(pend==p1) {
IOerror=1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) {
return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
}
template<class T> inline bool read(T &x) {
bool sign=0;
char ch=nc();
x=0;
for(; blank(ch); ch=nc());
if(IOerror)return false;
if(ch=='-')sign=1,ch=nc();
for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
if(sign)x=-x;
return true;
}
template<class T,class... U>bool read(T& h,U&... t) {
return read(h)&&read(t...);
}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
const int INF = 0x3f3f3f3f;
const int N = 2010;
struct node{
int x,y,k,c;
}a[N];
struct edge{
int u,v,w;
}e[N*N*2];
int f[N];
int find(int x){
return f[x]==x?x:f[x]=find(f[x]);
}
int dis(int x,int y){
return abs(a[x].x-a[y].x)+abs(a[x].y-a[y].y);
}
int cmp(edge x,edge y){
return x.w<y.w;
}
signed main() {
#ifdef xiaofan
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
int n;
read(n);
int cnt=0;
for(int i=1;i<=n;i++) read(a[i].x,a[i].y);
for(int i=0;i<=n;i++) f[i]=i;
for(int i=1;i<=n;i++) {
read(a[i].c);
e[++cnt]={0,i,a[i].c};
}
for(int i=1;i<=n;i++) read(a[i].k);
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
e[++cnt]={i,j,(a[i].k+a[j].k)*dis(i,j)};
}
}
sort(e+1,e+1+cnt,cmp);
int use=0,sum=0;
vector<int>dian;
vector<pair<int,int>>road;
for(int i=1;i<=cnt;i++){
int u=e[i].u;
int v=e[i].v;
int w=e[i].w;
int t1=find(u);
int t2=find(v);
if(t1!=t2){
f[t2]=t1;
sum+=w;
use++;
if(u==0) dian.push_back(v);
else road.push_back(mp(u,v));
if(use==n) break;
}
}
cout<<sum<<endl;
cout<<dian.size()<<endl;
for(auto x:dian) cout<<x<<" ";
cout<<endl;
cout<<road.size()<<endl;
for(auto x:road) cout<<x.fi<<" "<<x.se<<endl;
return 0;
}