OJ8-3 C. Slack Time 松弛时间

C. Slack Time
运行时间限制: 1000 运行内存限制: 65536
作者: scsxuke 是否specialjudge: False
题目描述
Given an Acyclic Graph as the figure (shared by QQ), delete one edge of activity, then calculate the slack time of the left nodes.
Output the slack time of a specified node

input
1 line of numbers seperated by commar, the first two are the nodes numbers of the edge to be deleted, the third gives the node number to be output the slack time

output
the slack time of the specified node

输入样例
2,5,5,
输出样例
1

#include <stdio.h>
#define inf 1e9
int main()
{
    int a[8][8];
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            a[i][j] = inf;
        }
    }

    a[1][2] = 3;
    a[1][3] = 3;
    a[1][4] = 6;
    a[2][4] = 2;
    a[2][5] = 5;
    a[3][4] = 3;
    a[3][6] = 3;
    a[4][5] = 2;
    a[4][6] = 2;
    a[4][7] = 5;
    a[5][7] = 3;
    a[6][7] = 4;

    int x1, x2, x;
    scanf("%d,%d,%d", &x1, &x2, &x);
    a[x1][x2] = inf;

    int array[130];
    int front = 0;
    int rear = -1;
    int size = 0;

    int E[8];
    int L[8];
    for (int i = 0; i < 8; i++)
    {

        E[i] = 0;
        L[i] = inf;
    }
    int v, w; // from v to w;
    array[++rear] = 1;
    size++;
    E[1] = 0;
    while (size != 0)
    {
        v = array[front++];
        size--;
        for (w = 1; w <= 7; w++)
        {
            if (a[v][w] != inf)
            {
                array[++rear] = w;
                size++;
                if (a[v][w] + E[v] > E[w])
                {
                    E[w] = a[v][w] + E[v];
                }
            }
        }
    }

    L[7] = E[7];
    front = 0;
    rear = -1;
    size = 0;
    array[++rear] = 7;
    size++;

    while (size != 0)
    {
        w = array[front++];
        size--;
        for (v = 1; v <= 7; v++)
        {
            if (a[v][w] != inf)
            {
                array[++rear] = v;
                size++;
                if (L[w] - a[v][w] < L[v])
                {
                    L[v] = L[w] - a[v][w];
                }
            }
        }
    }

    int result = 0;
    result = L[x] - E[x];
    printf("%d", result);
    return 0;
}
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值