错误代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x7f7f7f7f;//2139062143
typedef long long ll;
using namespace std;
int map1[10010][10010];
int visit[10010];
int lowdist[10010];
int n;
void Prim()
{
int sum = 0;
memset(visit,0,sizeof(visit));
for(int i=0; i<=n; i++)
{
lowdist[i] = map1[1][i];
}
int k;
visit[1] = 0;
for(int i=1; i<=n; i++)
{
int min2 = inf;
for(int j=0; j<=n; j++)
{
if(!visit[i] && lowdist[i] < min2)
{
min2 = lowdist[i];
k = i;
}
}
visit[k] = 1;
sum += lowdist[k];
for(int j=0; j<=n; j++)
{
if(!visit[j] && map1[k][j] < lowdist[j])
{
lowdist[j] = map1[k][j];
}
}
}
printf("%d\n",sum);
}
int main()
{
int m;
while(scanf("%d%d",&n,&m) != EOF)
{
memset(map1,inf,sizeof(map1));
int a,b,c;
for(int i=0; i<m; i++)
{
scanf("%d%d%d",&a,&b,&c);
map1[a][b] = map1[b][a] = c;
}
for(int i=1; i<=n; i++)
{
scanf("%d",&a);
if(a != -1)
map1[i][0] = map1[0][i] = a;
else
map1[i][0] = map1[0][i] = inf;
}
Prim();
}
return 0;
}