Http://lx.lanqiao.cn/problem.page?gpid=T16
Test instructions: N points, P-bar, n,p<=1e5. Each point has a right value of c[i], to choose a point to go through all points and return the minimum cost required?
It is easy to find that each side has experienced two times, when the Edge (U,v) reaches V at the first time ans+=c[v],v returns u Ans+=c[u] the construction edge is: Comfort two points (u,v) the cost of 2*w+c[u]+c[v], to find the MST can
#include <bits/stdc++.h>using namespace std;const int inf=1e9;const int n=2e5+20;struct node{int u,v,w;} E[n];int n,p,c[n],d[n],vis[n],ans;int Fa[n];bool CMP (node A,node b) {return A.W<B.W;} int find (int x) {if (fa[x]!=x) Fa[x]=find (fa[x]); return fa[x];} void Union (int x,int y) {int fx=find (x), Fy=find (y); fa[fx]=fy;} A void Kruskal () {for (int i=1;i<=n;i++) Fa[i]=i;sort (E,E+P,CMP) is synthesized for each of the two connected components at a minimum cost; for (int i=0;i<p;i++) {int u=e [I].u,v=e[i].v,w=e[i].w;if (Find (U)!=find (v)) {Union (u,v); ans+=w;}}} int main () {while (cin>>n>>p) {int mn=inf;ans=0;int u,v,w;for (int i=1;i<=n;i++) {cin>>c[i];mn=min (c[i],mn);//select Slepp Place, beginning}for (int i=0;i<p;i++) {Cin>>u>>v>>w;e[i].u=u,e[i].v=v;e[i].w=2*w+c [u]+c[v];//Comfort U,v Two cows required time}kruskal (); memset (vis,0,sizeof (VIS));cout<<ans+mn<<endl; }return 0;}
Algorithm Training Comfort Cow minimum spanning tree + construction