1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include<bits/stdc++.h> using namespace std; const int maxn=2e6+10; #define ll long long ll f[maxn],r[maxn]; typedef pair<ll,ll> pil; struct node { ll x;int y; }p[maxn]; struct Node { ll u, v, w; }P[maxn]; bool cmp(Node a,Node b) { return a.w<b.w; } bool cmp2(pil a,pil b) { return a.first <b.first; } ll find(ll x) { return f[x]!=x?f[x]=find(f[x]):x; } void join(int x,int y) { x=find(x); y=find(y); if(x!=y) f[x]=y; } vector<pil> s,ss; int main(){ ll n,pos,co; cin>>n; for(int i=0;i<=n;i++) f[i]=i; for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y; for(int i=1;i<=n;i++) { cin>>co;P[i].u=i;P[i].v=0;P[i].w=co; } for(int i=1;i<=n;i++) cin>>r[i]; pos=n+1; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) { ll mid=(abs(p[i].x-p[j].x)+abs(p[i].y-p[j].y))*(r[i]+r[j]); P[pos].u=j,P[pos].v=i,P[pos++].w=mid; } ll sum=0,a=0,b=0; sort(P+1,P+pos+1,cmp); for(int i=1;i<=pos;i++) { if(find(P[i].u)!=find(P[i].v)) { join(P[i].u,P[i].v); sum+=P[i].w; if(P[i].u!=0&&P[i].v!=0) a++,s.push_back(make_pair(P[i].u,P[i].v)); else b++,ss.push_back(make_pair(P[i].u,P[i].v)); } } cout<<sum<<endl; cout<<b<<endl; sort(ss.begin(),ss.end(),cmp2); for(int i=0;i<ss.size();i++) { ll a1 = ss[i].first, a2 = ss[i].second; if(a1) cout<<a1<<" "; else cout<<a2<<" "; } cout<<endl; cout<<a<<endl; for(int i=0;i<s.size();i++) { ll a1 = s[i].first, a2 = s[i].second; if (a1 > a2) swap(a1, a2); cout << a1 << " " << a2 << endl; } }
|