比赛 20110916 评测结果 AWWWWWWWWWA
题目名称 找工作 最终得分 18
用户昵称 feng 运行时间 1.528 s
代码语言 Pascal 内存使用 0.59 MiB
提交时间 2011-09-16 20:50:04
显示代码纯文本
program  tul;
const
  filename='jobhunt';
  inf=filename+'.in';
  ouf=filename+'.out';
  maxn=300;
var
  i,j,k,l,m,n,sum,max,d,p,c,s,be,x,y:longint;
  f:array[1..maxn]of boolean;
  a:array[1..maxn,1..maxn]of boolean;
  t:array[1..maxn,1..maxn]of longint;
  v:array[1..maxn]of longint;
procedure dfs(k:longint);
  var i,max:longint;
    begin
      for i:=1 to n do
        if a[k,i] then
          if f[i] then
            begin
              sum:=sum+d;
              if sum>v[i] then
                begin
                  max:=v[i];
                  v[i]:=sum;
                  f[i]:=false;

                  dfs(i);

                  f[i]:=true;
                end;
              sum:=sum-d;
            end
            else
              begin
                sum:=sum+d;
                if sum>v[i] then
                  begin
                    writeln('-1');
                    close(input);
                    close(output);
                    halt;
                  end;
                sum:=sum-d;
              end;
      for i:=1 to s do
        if t[k,i]<sum then
        if f[i] then
          begin
            sum:=sum-t[k,i];
            sum:=sum+d;
            if sum>v[i] then
              begin
                max:=v[i];
                v[i]:=sum;
                f[i]:=false;

                dfs(i);

                f[i]:=true;
              end;
            sum:=sum+d-t[k,i];
          end
          else
            begin
              sum:=sum+d-t[k,i];
                if sum>v[i] then
                  begin
                    writeln('-1');
                    close(input);
                    close(output);
                    halt;
                  end;
              sum:=sum-d+t[k,i];
            end;

    end;
begin
  assign(input,inf); reset(input);
  assign(output,ouf);rewrite(output);
  readln(d,m,n,s,be);
  fillchar(a,sizeof(a),false);
  fillchar(t,sizeof(t),10);
  fillchar(f,sizeof(f),true);
  for i:=1 to m do
    begin
      readln(x,y);
      a[x,y]:=true;
    end;
  for i:=1 to s do
    begin
      read(x,y);
      readln(t[x,y]);
    end;
  f[be]:=false;
  sum:=d;
  v[be]:=d;
  dfs(be);
  max:=0;
  for i:=1 to n do
    if max<v[i] then max:=v[i];
  writeln(max);
  close(input);close(output);
end.