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>
typedef struct graph
{
int weight[7][7];
int LastC[7];
int EarlyC[7];
} Graph;
int findmax(Graph g, int index)
{
int max = 0;
for (int i = 0; i < 7; i++)
{
if (g.weight[i][index] != 0)
{
if (g.EarlyC[i] + g.weight[i][index] > max)
max = g.EarlyC[i] + g.weight[i][index];
}
}
return max;
}
int findmin(Graph g, int index)
{
int min = 99999;
for (int i = 0; i < 7; i++)
{
if (g.weight[index][i] != 0)
{
if (g.LastC[i] - g.weight[index][i] < min)
min = g.LastC[i] - g.weight[index][i];
}
}
return min;
}
int main()
{
Graph g;
int n1, n2, need;
scanf("%d,%d,%d", &n1, &n2, &need);
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 7; j++)
{
g.weight[i][j] = 0;
}
g.LastC[i] = g.EarlyC[i] = 0;
}
g.weight[0][1] = 3;
g.weight[0][2] = 3;
g.weight[0][3] = 6;
g.weight[1][3] = 2;
g.weight[1][4] = 5;
g.weight[2][3] = 3;
g.weight[2][5] = 3;
g.weight[3][4] = 2;
g.weight[3][5] = 2;
g.weight[3][6] = 5;
g.weight[4][6] = 3;
g.weight[5][6] = 4;
g.weight[n1 - 1][n2 - 1] = 0;
g.EarlyC[0] = 0;
for (int i = 0; i < 7; i++)
{
int ret = findmax(g, i);
g.EarlyC[i] = ret;
}
g.LastC[6] = g.EarlyC[6];
for (int i = 7 - 2; i >= 0; i--)
{
int ret = findmin(g, i);
g.LastC[i] = ret;
}
printf("%d", g.LastC[need - 1] - g.EarlyC[need - 1]);
return 0;
}