比赛 |
20110916 |
评测结果 |
WWWWWWWWWWA |
题目名称 |
找工作 |
最终得分 |
9 |
用户昵称 |
苏轼 |
运行时间 |
0.004 s |
代码语言 |
C++ |
内存使用 |
0.30 MiB |
提交时间 |
2011-09-16 20:45:58 |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
using namespace std;
struct way_t {
int en, p;
way_t *next;
};
struct waylist {
way_t *head;
};
waylist way[300];
int boo[300], maxp[300], maxcurr;
int D, P, C, F, S;
void addway (waylist *l, const int en, const int p = 0)
{
way_t *newt = (way_t*)malloc(sizeof(way_t));
newt->en = en;
newt->p = p;
newt->next = l->head;
l->head = newt;
}
int go (const int wh, int cp)
{
cp += D;
if (boo[wh])
return cp>boo[wh] ? -1:D;
if (maxp[wh] > 0)
return wh;
boo[wh] = cp;
int mp = 0;
for (way_t *zz=way[wh].head; zz; zz=zz->next)
{
if (zz->p <=cp)
{
int tmp;
if ((tmp = go(zz->en, cp-zz->p)-zz->p) > mp)
mp = tmp;
if (tmp <= -1)
return -1;
}
}
boo[wh] = 0;
if (cp+mp>maxcurr)
maxcurr = cp+mp;
return (maxp[wh] = mp);
}
int main ()
{
freopen("jobhunt.in", "r", stdin);
freopen("jobhunt.out", "w", stdout);
scanf("%d %d %d %d %d", &D, &P, &C, &F, &S);
for (int i=0; i<P; i++)
{
int a, b;
scanf("%d %d", &a, &b);
addway(way+a, b);
}
for (int i=0; i<F; i++)
{
int a, b, p;
scanf("%d %d %d", &a, &b, &p);
addway(way+a, b, p);
}
if (go(S, 0) >= 0)
printf("%d\n", maxcurr);
else
printf("-1\n");
return 0;
}