-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1005.c
64 lines (51 loc) · 1.18 KB
/
1005.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#define BLD_NUM 100
int search(int (*mptr)[BLD_NUM], int bptr[], int dp[], int node, int desti)
{
int i, max = 0, result;
//if(dp[desti])
if(dp[desti] != -1)
return dp[desti];
for(i=0; i<node; i++)
if(mptr[i][desti])
{
result = search(mptr, bptr, dp, node, i);
if(result > max)
max = result;
}
// if(dp[desti] < bptr[desti] + max)
dp[desti] = bptr[desti] + max;
return dp[desti];
}
int main(void)
{
int i, j, cnt, node, way, desti, x, y;
int bld[BLD_NUM];
int mat[BLD_NUM][BLD_NUM];
int dp[BLD_NUM];
scanf("%d", &cnt);
while(cnt--)
{
// memset(met, 0, sizeof(met)); more than needs
scanf("%d %d", &node, &way);
for(i=0; i<node; i++)
for(j=0; j<node; j++)
mat[i][j] = 0;
for(i=0; i<node; i++)
dp[i] = -1; // bld can be 0
for(i=0; i<node; i++)
scanf("%d", &bld[i]);
for(i=0; i<way; i++)
{
scanf("%d %d", &x, &y);
mat[x-1][y-1] = 1;
}
scanf("%d", &desti);
printf("%d\n", search(mat, bld, dp, node, desti-1));
}
return 0;
}