比赛 20110916 评测结果 AAAAAAAATTA
题目名称 找工作 最终得分 81
用户昵称 Des. 运行时间 3.297 s
代码语言 Pascal 内存使用 0.73 MiB
提交时间 2011-09-16 21:57:48
显示代码纯文本
program jobhunt;
var a:array[1..220,1..220]of longint;
    b:array[1..220]of boolean;
    f:array[1..220]of int64;
    t,k,m,n,i,j,s0,p,st,x,z:longint;
    q:array[1..100000]of longint;
procedure search(i,s:longint);
var t,k,j:longint;
begin
if (i<>z)and(b[i]) then exit;
if (i=z)and(b[i])and(b[st])then
  begin
    if s>0 then
      begin
        writeln(-1);
        close(output);
        halt;
      end;
    exit;
  end;
b[i]:=true;
for j:=1 to n do
  if (a[i,j]>=0) then
    search(j,s+s0-a[i,j]);
b[i]:=false;
end;
begin
assign(input,'jobhunt.in');
reset(input);
assign(output,'jobhunt.out');
rewrite(output);
readln(s0,m,n,p,st);
for t:=1 to n do
  for k:=1 to n do
    a[t,k]:=-1;
for t:=1 to m do
  begin
    readln(i,j);
    a[i,j]:=0;
  end;
for t:=1 to p do
  begin
    readln(i,j,k);
    a[i,j]:=k;
  end;
fillchar(b,sizeof(b),false);
for z:=1 to n do
  search(z,0);
i:=0;
j:=1;
q[1]:=st;
fillchar(b,sizeof(b),false);
b[st]:=true;
for t:=1 to n do
  f[t]:=-maxlongint;
f[st]:=s0;
repeat
  inc(i);
  x:=q[i];
  for k:=1 to n do
    if (a[x,k]>=0)and(f[k]<f[x]+s0-a[x,k]) then
      begin
        f[k]:=f[x]+s0-a[x,k];
        if b[k]=false then
          begin
            inc(j);
            q[j]:=k;
            b[k]:=true;
          end;
      end;
  b[x]:=false;
until i=j;
i:=0;
for t:=1 to n do
  if f[t]>i then i:=f[t];
writeln(i);
close(output);
end.