我是编码新手,我不确定为什么这段代码会出现这个错误:运行时错误(SIGKILL)。谢谢。代码是天真的 Dijkstra 算法。此代码在批量测试用例上运行。因此是最外层的循环。样本输入: 3 3 2 1 2 5 2 3 7 1 3 3 3 1 2 4 1 3 7 2 3 1 1 3 3 1 1 2 4 1 3
输出 - 12 5 NO
#include <cstdio>
int weight [10003][10003];
bool seen [10003];
int dist[10003];
#define oo 100000000
int main(){
// freopen("dij.out","w",stdout);
int rounds;
scanf("%d",&rounds);
for(int i=0;i<rounds;i++){
for(int me=0;me<10003;me++){ //initialising for next batch
seen[me]=false;
}
for(int you=0;you<10003;you++){ // initialising for next batch
for(int u=0;u<10003;u++){
weight[you][u]=0;
}
}
int v,k;
scanf("%d %d",&v,&k);
for(int j=0;j<k;j++){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
weight[a][b]=c;
weight[b][a]=c;
}
for(int z=0;z<=v;z++){
dist[z]=oo;
}
int start,end;
scanf("%d %d",&start,&end);
dist[start]=0;
while(true){ //dijkstra's
int closest=-1;
for(int bla=1;bla<=v;bla++){
if(!seen[bla]&&(closest==-1||dist[bla]<dist[closest])){
closest=bla;
}
}
if(closest==-1){
break;
}
seen[closest]=true;
for(int adj=1;adj<=v;adj++){
if(weight[closest][adj]>0){
if(dist[closest]+weight[closest][adj]<dist[adj]){
dist[adj]=dist[closest]+weight[closest][adj];
}
}
}
}
if(dist[end]==oo){
printf("NO\n");
}else{
printf("%d\n",dist[end]);
}
}
}