Bootstrap

slack time松弛时间

在这里插入图片描述

#include <stdio.h>
#include <stdlib.h>
typedef struct table
{
    int EC;
    int LC;
}TABLE;
typedef struct table Table;

void initialize(int graph[8][8],int graph1[8][8],int a,int b);

int main()
{

    int graph[8][8];
    int graph1[8][8];
    int i,j;
    int a,b,x;
    Table T[8];
    scanf("%d,%d,%d,",&a,&b,&x);
    for(i=1;i<8;i++)
    {
        T[i].EC=0;
        T[i].LC=100;
    }
    T[1].EC=0;
    initialize(graph,graph1,a,b);
    int temp;
    for(i=1;i<8;i++)
    {
        for(j=1;j<8;j++)
        {
            if(graph[i][j]!=0)
            {
                temp=T[i].EC+graph[i][j];
                if(temp>T[j].EC)
                {
                    T[j].EC=temp;
                }

            }
        }
    }
    for(i=7;i>0;i--)
    {
        for(j=7;j>0;j--)
        {
            if(i==7&&j==7)
            {
                T[i].LC=T[i].EC;
            }
            else
            {
                if(graph1[i][j]!=0)
                {
                    temp=T[i].LC-graph1[i][j];
                    if(temp<T[j].LC)
                    {
                        T[j].LC=temp;
                    }
                }
            }
            
        }
    }
    printf("%d",T[x].LC-T[x].EC);
    /*printf("\n");
    for(i=1;i<8;i++)
    {
        printf("%d,",T[i].LC);
    }
    printf("\n");
    for(i=1;i<8;i++)
    {
        printf("%d,",T[i].EC);
    }*/
    return 0;
}

void initialize(int graph[8][8],int graph1[8][8],int a, int b)
{
    int i,j;
    for(i=0;i<8;i++)
    {
        for(j=0;j<8;j++)
        {
            graph[i][j]=0;
            graph1[i][j]=0;
        }
    }
    graph[1][2]=3;
    graph[1][4]=6;
    graph[1][3]=3;
    graph[2][4]=2;
    graph[3][4]=3;
    graph[3][6]=3;
    graph[4][5]=2;
    graph[4][6]=2;
    graph[4][7]=5;
    graph[5][7]=3;
    graph[6][7]=4;
    graph[2][5]=5;
    graph1[5][2]=5;
    graph1[2][1]=3;
    graph1[4][1]=6;
    graph1[3][1]=3;
    graph1[4][2]=2;
    graph1[4][3]=3;
    graph1[6][3]=3;
    graph1[5][4]=2;
    graph1[6][4]=2;
    graph1[7][4]=5;
    graph1[7][5]=3;
    graph1[7][6]=4;
    graph[a][b]=0;
    graph1[b][a]=0;
}
;