14 61 2 102 3 103 1 101 4 12 4 13 4 11 3 5 6
4/*Time:2014-8-30 21:51*/#include#include#includeusing namespace std;const int INF=1<<20;int minV=INF;int N,M;int map[505][510]; void Init(){scanf("%d%d",&N,&M);for(int i=0;i<=N;i++)for(int j=0;j<=N;j++){if(j!=i)map[i][j]=INF;else map[j][i]=0;}for(int i=0;iint a,b,c;scanf("%d%d%d",&a,&b,&c);map[a][b]=map[b][a]=c;}minV=INF;int cost;for(int i=0;iscanf("%d",&cost);minV=min(minV,cost);}}int Prim(){int d[1000];int Mst=0;bool vis[1000];memset(vis,0,sizeof(vis));for(int i=1;i<=N;i++)d[i]=map[1][i];vis[1]=true;for(int i=1;iint u=0,m=INF;for(int j=1;j<=N;j++){if(!vis[j]&&m>d[j]){m=d[j];u=j;}}vis[u]=true;if(d[u]==INF)return Mst;Mst+=d[u];for(int j=1;j<=N;j++){if(!vis[j]&&d[j]>map[u][j]){d[j]=map[u][j];}}}return Mst;}void solve(){int T;scanf("%d",&T);while(T--){Init();int Mst=Prim();printf("%d\n",Mst+minV);}}int main(){solve();return 0;}
/*Time:2014-8-30 21:51*/#include#include#includeusing namespace std;const int INF=1<<20;int minV=INF;int N,M;int map[505][510]; void Init(){scanf("%d%d",&N,&M);for(int i=0;i<=N;i++)for(int j=0;j<=N;j++){if(j!=i)map[i][j]=INF;else map[j][i]=0;}for(int i=0;iint a,b,c;scanf("%d%d%d",&a,&b,&c);map[a][b]=map[b][a]=c;}minV=INF;int cost;for(int i=0;iscanf("%d",&cost);minV=min(minV,cost);}}int Prim(){int d[1000];int Mst=0;bool vis[1000];memset(vis,0,sizeof(vis));for(int i=1;i<=N;i++)d[i]=map[1][i];vis[1]=true;for(int i=1;iint u=0,m=INF;for(int j=1;j<=N;j++){if(!vis[j]&&m>d[j]){m=d[j];u=j;}}vis[u]=true;if(d[u]==INF)return Mst;Mst+=d[u];for(int j=1;j<=N;j++){if(!vis[j]&&d[j]>map[u][j]){d[j]=map[u][j];}}}return Mst;}void solve(){int T;scanf("%d",&T);while(T--){Init();int Mst=Prim();printf("%d\n",Mst+minV);}}int main(){solve();return 0;}