Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1233
Well, finally is the Chinese question, haha ...
#include <iostream> #include <string> #include <cstdio> #include <cstring> #include <map> #include <queue> #include <cmath> #include <stack> #include <set> #include <vector> # Include<algorithm> #define LL long #define INF 1<<29 #define S (a) scanf ("%d", &a) #define CL (b) MEMS
ET (a,b,sizeof (a)) using namespace Std;
const int n=205;
int n,m,a,b,c;
String s1,s2;
int map[n][n];
int dist[n];
BOOL Vis[n];
int Prim () {CL (vis,false);
int i,res=0;
for (int i=1;i<=n;i++) dist[i]=map[1][i];
Vis[1]=true;
for (i=2;i<=n;i++) {int v=-1; for (int u=1;u<=n;u++) if (!vis[u]&& (v==-1| |
DIST[U]<DIST[V]) V=u;
if (v==-1) break;
RES+=DIST[V];
Vis[v]=true;
for (int u=1;u<=n;u++) dist[u]=min (Dist[u],map[v][u]);
} if (i<=n) return-1;
return res;
} int main () {while (~s (n)) {if (!n) is break; for (int i=1;i<= (n (n-1)/2); i++) {scanf ("%d%d%d", &a,&b,&c);
Map[a][b]=map[b][a]=c;
} printf ("%d\n", Prim ());
} return 0;
}