gpt4 book ai didi

c++ - 它给出了段错误。我正在尝试实现福特富克森算法,在这里我正在从文件中读取

转载 作者:行者123 更新时间:2023-11-28 03:34:44 25 4
gpt4 key购买 nike

<分区>

int main()
{
int i,j,k,l,m;
int maxflow=0;
int first,second,capac;

int residual[100][100];
//reading from file
FILE*fp;
fp=fopen("ford.txt","r");
fscanf(fp,"%d %d",&node,&edge);
cout<<"nodes are"<<node<<"\n"<<"edges are"<<edge<<"\n";
for(j=1;j<=node;j++)
{
for(k=1;k<=node;k++)
{
capacity[j][k]=0;
}
}
for(i=0;i<edge;i++)
{
fscanf(fp,"%d %d %d",&first,&second,&capac);
cout<<first<<"->"<<second<<"="<<capac<<"\n"; //it is printing this
capacity[first][second]=capac;//crashes here at last i/p i.e.1=edge-1

}
cout<<"abc"; //this is not printed
for(l=1;l<=node;l++)
{
for(m=1;m<=node;m++)
{
flow[l][m]=capacity[l][m];
flow[m][l]=0;
}
}
return 0;
}

它甚至没有在 cout 语句中打印“abc”。我正在尝试实现 Ford-Fulkerson 算法。在这里,我正在读取文件并初始化容量流矩阵。之后我调用了 maxflow 函数,我在这里省略了。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com