本文共 1082 字,大约阅读时间需要 3 分钟。
某工厂发现厂里的机器在生产产品时要消耗大量的原材料,也就是说,有大量的原材料变成了废物。因此厂里想找出消耗原材料最大的一条生产线路进行改造,以降低成本。厂里的生产线路是一个有向无环网络,有N台机器分别代表网络中的N个结点。弧< I,j >(i < j)表示原材料从机器i传输到机器j的损耗数量。
Input
第一行是两个整数N,M(N<=100,M<=1000),分别表示网络的结点个数和弧数。第二行至M+1行,每行三个整数A,B,C,表示弧上的损耗为C。
Output
仅一个整数,为损耗最大的线路的损耗量。
Sample Input
5 5
1 2 2 2 4 9 1 3 7 3 4 1 4 5 6Sample Output
17
求这张图的最长路
#include#include #include using namespace std;struct DT{ int to,next,l;}a[30000];int dis[200][200],head[10000],n,m,num,lt[10000];int h,t,v[10000],f[10000];long long Gun;void SPFA(int s){ memset(f,0,sizeof(f)); h=0,t=1,v[1]=s,dis[s][s]=0,f[s]=1; while(h++ dis[s][a[i].to]){ //把 <改成> dis[s][a[i].to]=dis[s][v[h]]+a[i].l; if(!f[a[i].to]){ v[++t]=a[i].to; f[a[i].to]=1; } } } f[v[h]]=0; }}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int x,y,s; scanf("%d%d%d",&x,&y,&s); a[++num].to=y,a[num].next=head[x],head[x]=num,a[num].l=s; } //dis不用赋初值 for(int g=1;g<=n;g++) SPFA(g); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(Gun 改成>
转载地址:http://pqnq.baihongyu.com/