| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位高手能给出边界的测试数据,一直找不出错误#include<stdio.h>
#define N 200
#define max 10000
int power[N][N]={0};//权值数组
bool search[N]={false};
int closest[N]={0};//记录点v 到S 中的最近点
int lowcost[N]={0};//记录点v 到S 中的最近点的距离
int main()
{
int i,j;
int point;
while(scanf("%d",&point)!=EOF)
{
for(i=1;i<=point;i++)
{
for(j=1;j<=point;j++)
scanf("%d",&power[i][j]);
}
for(i=1;i<=point;i++)
{
closest[i]=1;
lowcost[i]=power[i][1];
search[i]=false;
}
search[1]=true;
int Q;
scanf("%d",&Q);
int a,b;//接受输入的两个顶点及权值
for(i=1;i<=Q;i++)
{
scanf("%d%d",&a,&b);
search[a]=true;
search[b]=true;
}
for(i=1;i<=point&&search[i];i++)
{
for(j=1;j<=point;j++)
{
if((lowcost[j]>power[j][i])&&!search[j])
{
lowcost[j]=power[j][i];
closest[j]=i;
}
}
}
int cost=0;//记录最小生成树的总代价
for(i=1;i<=point;i++)
{
int temp=max;
int index=1;//记录找出的结点
for(j=1;j<=point;j++)
{
if((lowcost[j]<temp)&&!search[j])
{
temp=lowcost[j];
index=j;
}
}
search[index]=true;
cost+=power[index][closest[index]];
for(j=1;j<=point;j++)
{
if((lowcost[j]>power[j][index])&&!search[j])
{
lowcost[j]=power[j][index];
closest[j]=index;
}
}
}
printf("%d\n",cost);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator