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;
}