L3-004. 肿瘤诊断
题目链接:
BFS
之前尝试使用递归dfs,提交后发现有两个段错误,发现递归层数太多,然后改用bfs解决。
代码如下:
1 #include2 #include 3 #define N 505 4 #define MAX 5000 5 using namespace std; 6 int n,m,s,d; 7 int pro[N]; 8 int Map[N][N]; 9 bool mark[N];10 int sum[N];11 int path[N];12 int Distance[N];13 int person[N];14 int i,j;15 stack st;16 int main(void){17 freopen("in.txt","r",stdin);18 scanf("%d%d%d%d",&n,&m,&s,&d);19 for(i=0;i len)Map[i][j]=Map[j][i]=len;26 }27 for(i=0;i Distance[i]){42 m=Distance[i];43 k=i;44 }45 }46 if(m==MAX)break;47 mark[k]=1;48 for(i=0;i Distance[k]+Map[k][i]){51 Distance[i]=Distance[k]+Map[k][i];52 person[i]=person[k]+pro[i];53 path[i]=k;54 sum[i]=sum[k];/**not 1**/55 }else if(Distance[i]==Distance[k]+Map[k][i]){56 sum[i]+=sum[k];/**not ++**/57 if(person[i]